If new value is null use the value from a sequence : Sequence Value « Sequence « Oracle PL / SQL






If new value is null use the value from a sequence

 
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>

   
  








Related examples in the same category

1.Use sequence in insert command
2.Sequence current value and next value
3.Get Sequence next value
4.Sequence max value: 999999999999999999999999999
5.Set sequence max value
6.Use Sequence in a procedure
7.Automatically including unique sequence numbers during an INSERT.
8.Random value based on sequence