数据类型1,CUBRID学习笔记

作者:计算机知识

CUB凯雷德ID学习笔记 27 数据类型4,cubrid学习笔记

约束相比

---苏醒内容开端---

---恢复生机内容开端---

数字和字符串相比

字符串被转为double

SELECT i FROM t WHERE i <= all {'11','12'};

 

            i

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

            1

            2

            3

            4

豆蔻梢头 数字类型  注意小数的四舍五入难点

6枚举类型

字符串和日期时间相比较

字符串转为日期或时间

SELECT s FROM t2;

 

          s

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

      '01/01/2000'

      '01/01/1999'

      '01/01/1998'

 

SELECT s FROM t2 WHERE s <= ALL {date'02/02/1998',date'01/01/2000'};

 

          s

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

       '01/01/1998'

报错了

1数字型

语法

总计相比

 

<enum_type>

Date/Time Type Operand

假定日期是间操作是-操作. 重返的是微秒

必赢手机登录,SELECT date'2002-01-01' - datetime'2001-02-02 12:00:00 am';

 

   date '2002-01-01'- datetime '2001-02-02 12:00:00 am'

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

                                          28771200000

Type

Bytes

Mix

Max

Exact/approx.

SHORT
SMALLINT

2

-32,768

32,767

exact numeric

INTEGER
INT

4

-2,147,483,648

2,147,483,647

exact numeric

BIGINT

8

-9,223,372,036,854,775,808

9,223,372,036,854,775,807

exact numeric

NUMERIC
DECIMAL

16

precision p: 1
scale s: 0

precision p: 38
scale s: 38

exact numeric

FLOAT
REAL

4

-3.402823466E 38 (ANSI/IEEE 754-1985 standard)

3.402823466E 38
(ANSI/IEEE 754-1985 standard)

approximate numeric
floating point : 7

DOUBLE
DOUBLE PRECISION

8

-1.7976931348623157E 308 ANSI/IEEE 754-1985 standard)  

1.7976931348623157E 308(ANSI/IEEE 754-1985 standard)  

approximate numeric
floating point : 15

MONETARY

12

-3.402823466E 38

3.402823466E 38

approximate numeric

 

    : ENUM '(' <char_string_literal_list> ')'

同品种相比较看优先级

2  bit类型

数据类型1,CUBRID学习笔记。<char_string_literal_list>

Date/Time Type & String Type Operands

就是0和1   最大的bit字符串长度1,073,741,823

    : <char_string_literal_list> ',' CHAR_STRING

若果有 -操作的话 结果如下

           DATE: 返回天

TIME, TIMESTAMP:返回 秒

DATETIME:返回 毫秒

SELECT date'2002-01-01' '10';

 

  date '2002-01-01' '10'

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

  01/11/2002

 

SELECT date'2002-01-01'-'2001-01-01';

 

  date '2002-01-01'-'2001-01-01'

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

                    31536000000

 

-- 上面包车型地铁操作是不得以的

 

SELECT date'2002-01-01'-'10';

 

 In line 1, column 13,

 EPRADOROCR-V: 10不是日期类型.    

 

bit(n)  

    | CHAR_STRING

Numeric Type & String Type Operands

 

SELECT 4 '5.2';

 

                4 '5.2'

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

  9.199999999999999e 00

 

SELECT '2002-01-01' 1;

   ERROR: 不能把'2002-01-01'转为double类型

SELECT DATE'2002-01-01' 1;

  date '2002-01-01' 1

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

  01/02/2002

  • n must be a number greater than 0.
  • If the length of the string exceeds n, it is truncated and filled with 0s.
  • If a bit string smaller than n is stored, the remainder of the string is filled with 0s.

 

String Type Operand

字符串的测算操作重临double类型

SELECT '3'*'2';

 

                     '3'*'2'

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

       6.000000000000000e 00

   字符串的加操作为延续操作.  ( 具体跟对加号的含义的布置有关 plus_as_concat 在 cubrid.conf中 )

  • SELECT '1' '1';
  •  
  •                '1' '1'
  • ======================
  •                   '11'
  • 如果plus_as_concat  没安装则
  •  
  •                    '1' '1'
  • ==========================
  •      2.000000000000000e 00

An error will be returned if it cannot be converted to the corresponding type.

27 数据类型4,cubrid学习笔记 范围比较 数字和字符串比较 字符串被转为double SELECT i FROM t WHERE i = all {'11','12'}; i ============= 1...

Example

CREATE TABLE bit_tbl(a1 BIT, a2 BIT(1), a3 BIT(8), a4 BIT VARYING);

INSERT INTO bit_tbl VALUES (B'1', B'1', B'1', B'1');

INSERT INTO bit_tbl VALUES (0b1, 0b1, 0b1, 0b1);

INSERT INTO bit_tbl(a3,a4) VALUES (B'1010', B'1010');

INSERT INTO bit_tbl(a3,a4) VALUES (0xaa, 0xaa);

SELECT * FROM bit_tbl;

 

  a1                    a2                    a3                    a4

 

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

  X'8'                  X'8'                  X'80'                 X'8'

  X'8'                  X'8'                  X'80'                 X'8'

  NULL                  NULL                  X'a0'                 X'a'

  NULL                  NULL                  X'aa'                 X'aa'

BIT VARYING(n)

  • If the length of the string exceeds n, it is truncated and filled with 0s.
  • The remainder of the string is not filled with 0s even if a bit string smaller than n is stored.
  • n must be a number greater than 0.

CREATE TABLE tbl (

Example

CREATE TABLE bitvar_tbl(a1 BIT VARYING, a2 BIT VARYING(8));

INSERT INTO bitvar_tbl VALUES (B'1', B'1');

INSERT INTO bitvar_tbl VALUES (0b1010, 0b1010);

INSERT INTO bitvar_tbl VALUES (0xaa, 0xaa);

INSERT INTO bitvar_tbl(a1) VALUES (0xaaa);

SELECT * FROM bitvar_tbl;

 

  a1                    a2

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

  X'8'                  X'8'

  X'a'                  X'a'

  X'aa'                 X'aa'

  X'aaa'                NULL

 

INSERT INTO bitvar_tbl(a2) VALUES (0xaaa);

 

ERROR: Data overflow coercing X'aaa' to type bit varying.

3  日期型

  • The range of year in DATE is 0001 - 9999 AD.
  • By default, the range of a time value is represented by the 24-hour system
  • The range of TIMESTAMP is between 1970-01-01 00:00:01 - 2038-01-19 03 03:14:07 (GMT). For KST (GMT 9), values from 1970-01-01 00:00:01 to 2038-01-19 12:14:07 can be stored.

格式

  • DATE Type
  • YYYY-MM-DD
  • MM/DD/YYYY
  • TIME Type
  • HH:MM:SS ["AM"|"PM"]
  • DATETIME Type
  • YYYY-MM-DD HH:MM:SS[.msec] ["AM"|"PM"]
  • TIMESTAMP Type
  • YYYY-MM-DD HH:MM:SS ["AM"|"PM"]

 

Type

bytes

Min.

Max.

Note

DATE

4

0001-01-01

9999-12-31

As an exception, DATE '0000-00-00' format is allowed.

TIME

4

00:00:00

23:59:59

 

TIMESTAMP

4

1970-01-01 00:00:01 (GMT)
1970-01-01 09:00:01 (KST)

2038-01-19 03:14:07 (GMT)
2038-01-19 12:14:07 (KST)

As an exception, TIMESTAMP '0000-00-00 00:00:00' format is allowed.

DATETIME

8

0001-01-01 00:00:0.000

9999-12-31 23:59:59.999

As an exception, DATETIME '0000-00-00 00:00:00' format is allowed.

 

 

 4  字符串  

大旨也是varchar nvarchar之类的

CHAR or VARCHAR 长度 1,073,741,823

 NCHAR or NCHAR  长度  536,870,911

 CSQL语句长度8,192 KB

字符集 能够透过数据库的情状变量设置

转义字符和章程

  • ' : Single quotes (')
  • " : Double quotes (")
  • n : Newline, linefeed character
  • r : Carriage return character
  • t : Tab character
  • \ : Backslash
  • % : Percent sign (%). 
  • _ : Underbar (_). 

示例

接待转载,转载时请保留小编音讯。本文版权归自身持有,如有任何难题,请与自家关系wang2650@sohu.com 。 过错

 

SELECT LENGTH('\');

 

   char_length('')

 

CREATE TABLE t1 (a varchar(200));

INSERT INTO t1 VALUES ('aaabbb'), ('aaa%');

 

SELECT a FROM t1 WHERE a LIKE 'aaa%' escape '\';

 

  a

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

  'aaa%'

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

---复苏内容停止---

    color ENUM('red', 'yellow', 'blue')

);

结果

Value

Index Number

NULL

NULL

'red'

1

'yellow'

2

'blue'

3

 

 

 

 

 

 插入 INSERT into tbl values ('yellow'), ('red'), (2), ('blue');

结果

SELECT color FROM tbl;

 

  color

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

  yellow

  red

  yellow

  blue

 

SELECT color FROM tbl ORDER BY color ASC;

 

  color

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

  red

本文由bwin必赢发布,转载请注明来源

关键词: 开源软件 C# NET 教程 笔记