最后看看达梦中特有的写法,说是特有只是针对Oracle而言,这种语法早在SQLSERVER中就存在了:
SQL>SELECT TOP 2 *
2 FROM T
3 ORDER BY ID;
SELECT TOP 2 *
FROM T
ORDER BY ID;
id name create_date
1 1 TEST 2010-03-31
2 2 TEST 2010-03-31
2 rows got
time used: 31.185(ms) clock tick:52131540.
SQL>SELECT * FROM T
2 LIMIT 2 OFFSET 1;
SELECT * FROM T
LIMIT 2 OFFSET 1;
id name create_date
1 2 NEWNAME 2010-03-31
2 2 TEST 2010-03-31
2 rows got
time used: 0.469(ms) clock tick:772680.
2 FROM T
3 ORDER BY ID;
SELECT TOP 2 *
FROM T
ORDER BY ID;
id name create_date
1 1 TEST 2010-03-31
2 2 TEST 2010-03-31
2 rows got
time used: 31.185(ms) clock tick:52131540.
SQL>SELECT * FROM T
2 LIMIT 2 OFFSET 1;
SELECT * FROM T
LIMIT 2 OFFSET 1;
id name create_date
1 2 NEWNAME 2010-03-31
2 2 TEST 2010-03-31
2 rows got
time used: 0.469(ms) clock tick:772680.
前一个是获取前N条记录的方法,相当于Oracle标准分页方式,不过语法要比标准分页简单得多。后面一个语句是在结果集中获取指定位置开始的N条记录。
在Oracle中可以通过ROWNUM或分析函数实现同样的功能,不过语句要复杂一些。