If id is null, use the value from sequence : Create Sequence « Sequence « Oracle PL / SQL






If id is null, use the value from sequence

 

SQL>
SQL> create table myTable(
  2      id           number primary key,
  3      blob_content blob
  4  )
  5  /

Table created.

SQL>
SQL> create sequence myTable_seq
  2  /

Sequence created.

SQL>
SQL> create or replace trigger biu_myTable
  2      before insert or update on myTable
  3      for each row
  4  begin
  5      if :new.id is null then
  6          select myTable_seq.nextval into :new.id from dual;
  7      end if;
  8  end;
  9  /

Trigger created.

SQL> drop table myTable;

Table dropped.

SQL> drop sequence myTable_seq;

Sequence dropped.

   
  








Related examples in the same category

1.Create a SEQUENCE and retrieve the value
2.CREATE SEQUENCE myTableIDSeq INCREMENT BY 1 START WITH 1000;
3.Use dual table to check sequence
4.create sequence emps_seq start with 501 increment by 10