Simulating autoincrement in Oracle
From: John <xertroyt_at_yahoo.com>
Date: 11 Apr 2002 19:04:24 -0700
Message-ID: <1ea65a.0204111804.7549c01c_at_posting.google.com>
Date: 11 Apr 2002 19:04:24 -0700
Message-ID: <1ea65a.0204111804.7549c01c_at_posting.google.com>
I recently ported some code from DB2 (which has an autoincrement
feature for column values) and needed to simulate that somehow in
Oracle.
Here's what I came up with:
This seems to work fine, but I was wondering if anyone sees any
gotchas.
John
create or replace trigger user.table_autoincrement
before insert on user.table
for each row
begin
if :new.col is null then
select user.table_s.nextval
into :new.col
from dual;
end if;
end table_autoincrement;