Skip to Main Content
  • Questions
  • Inserting primary key from sequence via Pro*C

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Johan.

Asked: March 25, 2006 - 9:38 am UTC

Last updated: March 29, 2006 - 7:04 am UTC

Version: 8.1.6

Viewed 1000+ times

You Asked

Tom

I have been looking through the supplied documentation, but I don't see anything on inserting a primary key column value based on a sequence from Pro*C.

I.e. I want to do something like:

insert into data
(a, b, c)
values (seq.nextval, :bval, :cval)

Also, how do I do this (insert the primary key from a sequence) if I insert using a record structure, and lastly, how do I do this if I insert using an array of records?

The reason for basing the primary key on a sequence, is that other processes could also insert into the table, and I need a central generator of sequence numbers.


and Tom said...

you would do it exactly as you have shown, no different than

insert into data (b,c) values ( :bval, :cval );

would be - as far as pro*c is concerned, the sequence "doesn't exist", it only sees the BINDS - that is what pro*c is concerned about.

So, just ignore the fact that the sequence is there - because Pro*c ignores it.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Primary key trigger?

JS, March 28, 2006 - 11:09 pm UTC

Tom,

Do you then imply that I should create a before insert trigger on the data table in order to populate the primary key from the sequence?

The only potential issue with this (as you have indicated in other posts) is that this is less performant compared to referencing the sequence in the insert statement.

Tom Kyte
March 29, 2006 - 7:04 am UTC

no, not at all?

I just said "it will as if it were not there at all - pro*c won't see the sequence"


Just code it right in the insert - don't use a trigger.