• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get id of auto-number

 
Claudia Vaz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I have a field in Oracle database that increments throught a sequence.
When i do a insert the field is incremented. How can i get the number in that field?
Thanks
Claudia Vaz
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Claudia,
Since Oracle 8i (I believe), INSERT and UPDATE (SQL) statements have an optional RETURNING clause.
I saw no mention in your post of which Oracle version you are using, so I will assume the latest version. Therefore you can read the Oracle9i SQL Reference manual for details.
However, you need to "wrap" your INSERT .. RETURNING statement in a PL/SQL function that returns the value that is assigned by the (Oracle) sequence. I haven't checked, but you may find examples of how to do this, either in the documentation (mentioned above) or amongst the JDBC How-To Documents at Oracle's Technet Web site.
(That's how I learned how to do it!)
Good Luck,
Avi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic