技术开发 频道

专家点评:达梦6.0试用之SQL篇

  首先测试DML语句,达梦数据库支持SQL92标准,且兼容Oracle8i的语法,下面测试一下:

SQL>INSERT INTO T
2   VALUES (1, 'TEST', SYSDATE);
INSERT INTO T
VALUES (1, 'TEST', SYSDATE)
1 rows affected
time used:
0.343(ms) clock tick:551330.
SQL
>INSERT INTO T
2   VALUES (2, 'TEST AGAIN', TO_DATE('2010-3-31', 'YYYY-MM-DD'));
INSERT INTO T
VALUES (2, 'TEST AGAIN', TO_DATE('2010-3-31', 'YYYY-MM-DD'))
1 rows affected
time used:
0.516(ms) clock tick:848580.
SQL
>UPDATE T
2   SET NAME = 'NEWNAME'
3   WHERE ID = 2;
UPDATE T
SET NAME = 'NEWNAME'
WHERE ID = 2;
1 rows affected
time used:
0.498(ms) clock tick:818000.
SQL
>INSERT INTO T
2   SELECT ROWNUM + ID, NAME, CREATE_DATE
3   FROM T;
INSERT INTO T
SELECT ROWNUM + ID, NAME, CREATE_DATE
FROM T;
2 rows affected
time used:
67.481(ms) clock tick:112655890.
SQL
>COMMIT;
COMMIT;
time used:
11.671(ms) clock tick:19334860.
SQL
>SELECT * FROM T;
SELECT * FROM T;
id              name            create_date
1       1       TEST    2010-03-31
2       2       NEWNAME 2010-03-31
3       2       TEST    2010-03-31
4       4       NEWNAME 2010-03-31
4 rows got
time used:
0.385(ms) clock tick:631120.
SQL
>DELETE T WHERE ID = 3;
DELETE T WHERE ID = 3;
0 rows affected
time used:
0.442(ms) clock tick:721900.
SQL
>DELETE T WHERE ID = 4;
DELETE T WHERE ID = 4;
1 rows affected
time used:
0.475(ms) clock tick:780110.
SQL
>SELECT * FROM T;
SELECT * FROM T;
id              name            create_date
1       1       TEST    2010-03-31
2       2       NEWNAME 2010-03-31
3       2       TEST    2010-03-31
3 rows got
time used:
0.321(ms) clock tick:520970.

  最基本的SELECT、INSERT、UPDATE、DELETE操作没有问题,甚至连ORACLE语法中的ROWNUM都支持。

  在ISQL显示结果中,有一个自动的行号显示,但是列名显示的时候没有将这一位空出来,使得ID列跑到了行号的位置上,比较容易引起误解。

SQL>MERGE INTO T
2   USING (SELECT ID + 1 ID, NAME, CREATE_DATE FROM T) T1
3   ON (T.ID = T1.ID)
4   WHEN MATCHED THEN UPDATE
5   SET T.NAME = T1.NAME, T.CREATE_DATE = T1.CREATE_DATE
6   WHEN NOT MATCHED THEN INSERT
7   VALUES (T1.ID, T1.NAME, T1.CREATE_DATE);
第1行:
'INTO'附近有语法错误
SQL
>SELECT * FROM T
2   START WITH ID = 1
3   CONNECT BY PRIOR ID = ID + 1;
SELECT * FROM T
START
WITH ID = 1
CONNECT
BY PRIOR ID = ID + 1;
id              name            create_date
1       1       TEST    2010-03-31
1 rows got
time used:
54.497(ms) clock tick:90706490.

  Oracle9i新增的MERGE语句果然是不支持的,而Oracle特有的树形查询居然是可以的,甚至连LEVEL伪列都是支持的:

SQL>SELECT T.*, LEVEL
2   FROM T
3   START WITH ID = 1
4   CONNECT BY ID = PRIOR ID + 1;
SELECT T.*, LEVEL
FROM T
START
WITH ID = 1
CONNECT
BY ID = PRIOR ID + 1;
id              name            create_date            
LEVEL
1       1       TEST    2010-03-31      1
2       2       NEWNAME 2010-03-31      2
3       2       TEST    2010-03-31      2
3 rows got
time used:
35.683(ms) clock tick:59512460.
0
相关文章