********************************************************************************
比如有下面数据
no id
1 a
2 b
4 d
我登陆的时候,先判断no,发现3不存在,就登陆到3去。如果3存在,那就取最大的4+1...
请问这个代码要怎么实现?
测试数据
CREATE TABLE T(NO NUMBER, ID VARCHAR2(10));
INSERT INTO T VALUES(1,'A');
INSERT INTO T VALUES(2,'B');
INSERT INTO T VALUES(6,'E');
INSERT INTO T VALUES(7,'F');
COMMIT;
SELECT NVL( MAX (NO), 0 ) + 1 NO
FROM ( SELECT NO, NO - ROW_NUMBER() OVER ( ORDER BY NO) X FROM T)
WHERE X =
( SELECT MIN (X)
FROM ( SELECT NO, NO - ROW_NUMBER() OVER ( ORDER BY NO) X FROM T));