将子查询作为查询列的方式居然也是支持的,这是没有想到的。
SQL>SELECT DECODE(ID, 1, 'A', 2, 'B', 'C')
2 FROM T;
SELECT DECODE(ID, 1, 'A', 2, 'B', 'C')
FROM T;
1 A
2 B
3 B
4 C
4 rows got
time used: 32.734(ms) clock tick:54721350.
SQL>SELECT CASE ID WHEN 1 THEN 'A' WHEN 2 THEN 'B' ELSE 'C' END
2 FROM T;
SELECT CASE ID WHEN 1 THEN 'A' WHEN 2 THEN 'B' ELSE 'C' END
FROM T;
1 A
2 B
3 B
4 C
4 rows got
time used: 0.439(ms) clock tick:724740.
2 FROM T;
SELECT DECODE(ID, 1, 'A', 2, 'B', 'C')
FROM T;
1 A
2 B
3 B
4 C
4 rows got
time used: 32.734(ms) clock tick:54721350.
SQL>SELECT CASE ID WHEN 1 THEN 'A' WHEN 2 THEN 'B' ELSE 'C' END
2 FROM T;
SELECT CASE ID WHEN 1 THEN 'A' WHEN 2 THEN 'B' ELSE 'C' END
FROM T;
1 A
2 B
3 B
4 C
4 rows got
time used: 0.439(ms) clock tick:724740.
达梦还支持DECODE函数和CASE语法。
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.385(ms) clock tick:630330.
SQL>DELETE T WHERE ID = 2 AND ROWNUM = 1;
DELETE T WHERE ID = 2 AND ROWNUM = 1;
1 rows affected
time used: 0.611(ms) clock tick:1004030.
SQL>ALTER TABLE T ADD PRIMARY KEY (ID);
ALTER TABLE T ADD PRIMARY KEY (ID);
time used: 14.329(ms) clock tick:23647990.
SQL>ALTER TABLE T1 ADD PRIMARY KEY (ID);
ALTER TABLE T1 ADD PRIMARY KEY (ID);
time used: 12.599(ms) clock tick:20886900.
SQL>UPDATE
2 (SELECT T.ID, T.NAME
3 FROM T, T1
4 WHERE T.ID = T1.ID)
5 SET NAME = 'A';
第2行: '('附近有语法错误
SQL>UPDATE T A
2 SET (NAME, CREATE_DATE) =
3 (SELECT NAME, CREATE_DATE FROM T WHERE ID = A.ID);
第3行: 'SELECT'附近有语法错误
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.385(ms) clock tick:630330.
SQL>DELETE T WHERE ID = 2 AND ROWNUM = 1;
DELETE T WHERE ID = 2 AND ROWNUM = 1;
1 rows affected
time used: 0.611(ms) clock tick:1004030.
SQL>ALTER TABLE T ADD PRIMARY KEY (ID);
ALTER TABLE T ADD PRIMARY KEY (ID);
time used: 14.329(ms) clock tick:23647990.
SQL>ALTER TABLE T1 ADD PRIMARY KEY (ID);
ALTER TABLE T1 ADD PRIMARY KEY (ID);
time used: 12.599(ms) clock tick:20886900.
SQL>UPDATE
2 (SELECT T.ID, T.NAME
3 FROM T, T1
4 WHERE T.ID = T1.ID)
5 SET NAME = 'A';
第2行: '('附近有语法错误
SQL>UPDATE T A
2 SET (NAME, CREATE_DATE) =
3 (SELECT NAME, CREATE_DATE FROM T WHERE ID = A.ID);
第3行: 'SELECT'附近有语法错误