• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ROWID on insert on Oracle DB

 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I'm working on a web application with Oracle on my back end. I have an insert statement that goes like this:

INSERT INTO users (users.id,users.first_name,users.last_name,users.manager) VALUES (USERS_SEQ.NEXTVAL,'Alice','Cooper',4);

I'm using the instructions according to the post made on StackOverFlow: http://stackoverflow.com/questions/1376218/is-ther-a-way-to-retrieve-the-autoincrement-id-from-a-prepared-statement

I'm trying to work with METHOD 1 in the post.

The SQL is encapsulated in a class called Query.

My code for the insert goes like this:



The printout to the console is: Database.executeInsertUpdate - rid: oracle.sql.ROWID@481a3391

What am I supposed to do with the value of rid? That's not what I was expecting. How am I supposed to get an id value from that?

Alan
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the post you're referring to states, the method 1 can only give you the row id. It is a physical address of the newly created row. You can use it in subsequent queries, but for obtaining the generated key it really isn't very useful, since you'd have to run another query against the database, and you're using the return generated key functionality to avoid exactly that.

To sum it up: method 1 doesn't do what you want. You need to use method 2 mentioned in the article.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic