charlie tsai
charlie tsai

Reputation: 285

Create sequence with sql result in it

I have a sequence like this

begin
 if :new."ID" is null then
     select to_number(sys_guid(),'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') into :new.id from dual;
  end if;

is there a way to set the ID to be the next upcoming ID in the table?

For example:

if my current last row ID is 5

I want the new.id to be 6, so when the INSERT executes then it would have ID of 6

Upvotes: 2

Views: 94

Answers (1)

developer_hatch
developer_hatch

Reputation: 16224

IDENTITY column is now available on Oracle 12c:

create table t1 (
    id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
    info VARCHAR2(10)
    );

Upvotes: 1

Related Questions