Example of Oracle Sequence
Example of Oracle Sequence
Topic Introduction: Example of Oracle Sequence
Structure:
CREATE SEQUENCE schema_name.sequence_name[INCREMENT BY interval][START WITH first_number][MAXVALUE max_value | NOMAXVALUE][MINVALUE min_value | NOMINVALUE][CYCLE | NOCYCLE][CACHE cache_size | NOCACHE][ORDER | NOORDER];
Create Sequence
CREATE SEQUENCE seq_empidpk INCREMENT BY 1START WITH 1MINVALUE 1MAXVALUE 999999999CYCLECACHE 20;
Check Current Value
SELECT seq_empidpk.CURRVAL FROM DUAL;
Check Next Value
SELECT seq_empidpk.NEXTVAL FROM DUAL;
Check Next Ten Value
SELECT seq_empidpk.NEXTVALFROM DUALCONNECT BY LEVEL <= 10;
Create TriggerUsing Sequence
CREATE OR REPLACE TRIGGER trig_empidpkBEFORE INSERTON employeesFOR EACH ROWBEGINIF :new.employee_id IS NULLTHENSELECT seq_empidpk.NEXTVAL INTO :new.employee_id FROM DUAL;--:new.employee_id := seq_empidpk.NEXTVAL;END IF;END;
No comments