If new value is null use the value from a sequence : Inserting « Trigger « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> create table myTable (id number);

Table created.

SQL>
SQL> create sequence wo_seq;



SQL>
SQL> create or replace trigger trg_id before insert
  2  on myTable
  3  for each row
  4  when (new.id is null)
  5  begin
  6     select wo_seq.nextval into :new.id from dual;
  7  end;
  8  /

Trigger created.

SQL>
SQL> drop table myTable;

Table dropped.

SQL>








28.16.Inserting
28.16.1.Trigger that logs actions for inserting actions
28.16.2.React to Inserting and Updating actions
28.16.3.If new value is null use the value from a sequence