|
-
Use a sequence, with a sequence you can generate unique integers. If you use MAX(deptno)+1, you can get duplicate values when rows are inserted from different sessions;
CREATE SEQUENCE dept_seq;
CREATE OR REPLACE TRIGGER dept_trig
BEFORE INSERT
ON dept
FOR EACH ROW
new_deptno NUMBER;
BEGIN
SELECT dept_seq.NEXTVAL
INTO new_deptno
FROM dual;
:new.deptno := new_deptno;
END;
/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|