INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

Return PK value after Insert - Oracle

Return PK value after Insert - Oracle

(OP)
I have a table in Oracle DB with a Primary Key that gets populated on Insert by a trigger on the table - the trigger gets the next sequence number from a sequence I created for the table and uses that for the value of the PK on insert. Now I would like to be able to return that PK value from my insert statement and use it as Foreign Key in another (child) table. All of that is done in VB code, not a Stored Procedure.

Is there some combination of Insert statement that returns PK used in that Insert? From the same transaction?

I know I can do: Select Max(PK_Field) as MyPKValue from SomeTable, but this way I may get somebody else's PK, not necessary mine (if somebody else issued another Insert statement). The same goes if I ask for current value from my sequence, not very safe bet either.

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Return PK value after Insert - Oracle

Can't you use an output parameter to do this?

RE: Return PK value after Insert - Oracle

(OP)
I have something like this in my code:

CODE

strSQL = "Insert Into SomeTable (FieldA, ...)" & _
    " Values  (123, ...) "

MyConnection.Execute strSQL 

What do you mean when you say: "output parameter"?

Have fun.

---- Andy

There is a great need for a sarcasm font.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close