CUBRID学习笔记 26 数据类型3cubrid教程

2022-04-08 00:00:00 集合 字符串 类型 数字 转为

接上面的集合

集合之 set 

每个集合元素是不同的值, 但是类型只能是一种.也可以有其他表的记录 如下

CREATE TABLE set_tbl ( col_1 set(CHAR(1)));

INSERT INTO set_tbl VALUES ({'c','c','c','b','b','a'});

INSERT INTO set_tbl VALUES ({NULL});

INSERT INTO set_tbl VALUES ({''});

SELECT * FROM set_tbl;

  col_1

======================

{'a', 'b', 'c'}

{NULL}

{' '}

SELECT CAST(col_1 AS MULTISET), CAST(col_1 AS LIST) FROM set_tbl;

   cast(col_1 as multiset)   cast(col_1 as sequence)

============================================

  {'a', 'b', 'c'}  {'a', 'b', 'c'}

  {NULL}  {NULL}

  {' '}  {' '}

INSERT INTO set_tbl VALUES ('');

ERROR: Cannot coerce '' to type set.

集合 MULTISET 

和set差不多.但是元素的内容可重复

CREATE TABLE multiset_tbl ( col_1 multiset(CHAR(1)));

INSERT INTO multiset_tbl VALUES ({'c','c','c','b','b', 'a'});

SELECT * FROM multiset_tbl;

  col_1

======================

  {'a', 'b', 'b', 'c', 'c', 'c'}

SELECT CAST(col_1 AS SET), CAST(col_1 AS LIST) FROM multiset_tbl;

   cast(col_1 as set)   cast(col_1 as sequence)

============================================

  {'a', 'b', 'c'}  {'c', 'c', 'c', 'b', 'b', 'a'}

集合 之list

可重复的,但是是有序的.保持插入前的顺序.list本身不会对内容排序.

CREATE TABLE list_tbl ( col_1 list(CHAR(1)));

INSERT INTO list_tbl VALUES ({'c','c','c','b','b', 'a'});

SELECT * FROM list_tbl;

  col_1

======================

  {'c', 'c', 'c', 'b', 'b', 'a'}

SELECT CAST(col_1 AS SET), CAST(col_1 AS MULTISET) FROM list_tbl;

   cast(col_1 as set)  cast(col_1 as multiset)

============================================

  {'a', 'b', 'c'}  {'a', 'b', 'b', 'c', 'c', 'c'}

隐式转换

 

From \ To

DATETIME

DATE

TIME

TIMESTAMP

DOUBLE

FLOAT

NUMERIC

BIGINT

DATETIME

-

O

O

O

    

DATE

O

-

 

O

    

TIME

  

-

     

TIMESTAMP

O

O

O

-

    

DOUBLE

    

-

O

O

O

FLOAT

    

O

-

O

O

NUMERIC

    

O

O

-

O

BIGINT

    

O

O

O

-

INT

   

O

O

O

O

O

SHORT

    

O

O

O

O

MONETARY

    

O

O

O

O

BIT

        

VARBIT

        

CHAR

O

O

O

O

O

O

O

O

VARCHAR

O

O

O

O

O

O

O

O

NCHAR

O

O

O

O

O

O

O

O

VARNCHAR

O

O

O

O

O

O

O

O

相关文章