Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Automatic numbering on primary key (without sequence)

The CainNov 30 2012 — edited Nov 30 2012
Hello,

i was wondering how to make automatic numbering of primary key without using sequence when "on" insert.

At the moment i am using trigger:
TRIGGER "scott"."do_numbers" BEFORE INSERT ON "scott"."test" 
REFERENCING NEW AS NEW FOR EACH ROW 

declare
 pragma autonomous_transaction;
begin

SELECT
 nvl(MAX(ID),0)+1
 INTO :NEW.ID
  FROM test;
commit;
END;
the above trigger works when i am inserting row by row. But now i tried to insert 300 rows at once. Here insert fails ... i think there should be commit after each insert (thats what i think).

Can someone explain it to me how can this "automatic" numbering can be done when inserting large number or rows from one table to another at once?

thank you!
This post has been answered by BluShadow on Nov 30 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 28 2012
Added on Nov 30 2012
14 comments
865 views