EMP_NO EMP_NAME
---------------------- ----------
1 mohan
2 ram
3 sysytem
4 chandra
5 screen
6 admin
7 manajor
8 project
9 keybord
10 mouse
11 monitor
使用上表中的最大值如何生成序列
答案 0 :(得分:0)
插入表格
INSERT INTO TABLE_NAME(EMP_NO,EMP_NAME) VALUES(选择SEQ.NEXTVAL FROM DUAL,......);
否则(无需创建序列)
select max(EMP_NO)+1 from EMP_TABLE
答案 1 :(得分:0)
你想从max(emp_no)+ 1开始吗? 如果是,请使用此
DECLARE
EX NUMBER;
BEGIN
SELECT
MAX ( EMP_NO )
+ 1
INTO
EX
FROM
EMP;
IF EX > 0
THEN
BEGIN
EXECUTE IMMEDIATE 'DROP SEQUENCE SQ_NAME';
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
EXECUTE IMMEDIATE
'CREATE SEQUENCE SQ_NAME INCREMENT BY 1 START WITH '
|| EX
|| ' NOCYCLE CACHE 20 NOORDER';
END IF;
END;