Create Sequence/Trigger in Oracle
Use the following script
DROP SEQUENCE SEQNAME;
CREATE SEQUENCE SEQNAME
START WITH 1
MAXVALUE 9999999999
MINVALUE 1
NOCYCLE
NOCACHE
NOORDER;
CREATE OR REPLACE TRIGGER TRIGGERNAME
BEFORE INSERT
ON TABLENAME
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
SELECT SEQNAME.NEXTVAL
INTO :NEW.PRIMARYKEYNAME
FROM DUAL;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR('-20000','TRIGGERNAME');
END;
/
Greetz,
G
Labels: Oracle
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home