下面看看数值类型:
SQL>create table t_num
2 (c1 number,
3 c2 number(4, 1),
4 c3 number(4, -1),
5 c4 number(2, 3));
第4行: '-'附近有语法错误
SQL>create table t_num
2 (c1 number,
3 c2 number(4, 1),
4 c4 number(2, 3));
create table t_num
(c1 number,
c2 number(4, 1),
c4 number(2, 3));
无效的数据类型.error code = -2520
SQL>create table t_num
2 (c1 number,
3 c2 number(4, 1));
create table t_num
(c1 number,
c2 number(4, 1));
time used: 42.803(ms) clock tick:71554500.
2 (c1 number,
3 c2 number(4, 1),
4 c3 number(4, -1),
5 c4 number(2, 3));
第4行: '-'附近有语法错误
SQL>create table t_num
2 (c1 number,
3 c2 number(4, 1),
4 c4 number(2, 3));
create table t_num
(c1 number,
c2 number(4, 1),
c4 number(2, 3));
无效的数据类型.error code = -2520
SQL>create table t_num
2 (c1 number,
3 c2 number(4, 1));
create table t_num
(c1 number,
c2 number(4, 1));
time used: 42.803(ms) clock tick:71554500.
虽然达梦支持数值类型NUMBER和Oracle的NUMBER类型十分相似,但是二者还是有区别的,显然达梦不支持标度小于0的情况,而且不支持精度小于标度的情况,而这些情况在Oracle中都是支持的,下面是Oracle中的情况:
SQL> create table t_num
2 (c1 number,
3 c2 number(4, 1),
4 c3 number(4, -1),
5 c4 number(2, 3));
表已创建。
SQL> insert into t_num
2 values (1, 234.4, 3225, 0.023);
已创建 1 行。
SQL> select * from t_num;
C1 C2 C3 C4
---------- ---------- ---------- ----------
1 234.4 3230 .023
2 (c1 number,
3 c2 number(4, 1),
4 c3 number(4, -1),
5 c4 number(2, 3));
表已创建。
SQL> insert into t_num
2 values (1, 234.4, 3225, 0.023);
已创建 1 行。
SQL> select * from t_num;
C1 C2 C3 C4
---------- ---------- ---------- ----------
1 234.4 3230 .023
虽然NUMBER类型和Oracle的NUMBER类型并不完全一致,但是二者对于精度和标度的描述还是一致的。不过Oracle如果NUMBER不指定精度,则默认是38,而在达梦中,默认是20。
SQL>insert into t_num values
2 (1234567890123456789012, 123.1);
insert into t_num values
(1234567890123456789012, 123.1)
数据溢出.error code = -2502
SQL>create table t_num2
2 (c1 number(*, 0));
第2行: '*'附近有语法错误
2 (1234567890123456789012, 123.1);
insert into t_num values
(1234567890123456789012, 123.1)
数据溢出.error code = -2502
SQL>create table t_num2
2 (c1 number(*, 0));
第2行: '*'附近有语法错误
另外达梦中也不支持NUMBER(*, 0)的写法。
达梦和SQLSERVER、SYBASE等数据库一样,对于表示整数的数据类型实现了自增列:
SQL>CREATE TABLE T_INC
2 (ID NUMBER(5, 0) IDENTITY (1, 2),
3 NAME VARCHAR);
CREATE TABLE T_INC
(ID NUMBER(5, 0) IDENTITY (1, 2),
NAME VARCHAR);
time used: 15.516(ms) clock tick:25924810.
SQL>INSERT INTO T_INC (NAME)
2 VALUES ('A');
INSERT INTO T_INC (NAME)
VALUES ('A')
1 rows affected
time used: 36.438(ms) clock tick:60908390.
SQL>INSERT INTO T_INC (NAME)
2 VALUES ('B');
INSERT INTO T_INC (NAME)
VALUES ('B')
1 rows affected
time used: 0.655(ms) clock tick:1082480.
SQL>SELECT * FROM T_INC;
SELECT * FROM T_INC;
ID NAME
1 1 A
2 3 B
2 rows got
time used: 1.769(ms) clock tick:2943530.
2 (ID NUMBER(5, 0) IDENTITY (1, 2),
3 NAME VARCHAR);
CREATE TABLE T_INC
(ID NUMBER(5, 0) IDENTITY (1, 2),
NAME VARCHAR);
time used: 15.516(ms) clock tick:25924810.
SQL>INSERT INTO T_INC (NAME)
2 VALUES ('A');
INSERT INTO T_INC (NAME)
VALUES ('A')
1 rows affected
time used: 36.438(ms) clock tick:60908390.
SQL>INSERT INTO T_INC (NAME)
2 VALUES ('B');
INSERT INTO T_INC (NAME)
VALUES ('B')
1 rows affected
time used: 0.655(ms) clock tick:1082480.
SQL>SELECT * FROM T_INC;
SELECT * FROM T_INC;
ID NAME
1 1 A
2 3 B
2 rows got
time used: 1.769(ms) clock tick:2943530.