Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Location
    Lahore, Pakistan
    Posts
    5

    Question Unanswered: insert and select in one statement

    using MS Sql server and VB i can execute two queries Insert and select in one statement e.g. (insert into (....) values (...) Select @@Identity).
    how can i do the same thing using Oracle and VB. ???
    It gives error. here's what i want to do.
    (insert into table1 (...) values (...) Select table1_sequence.currval from dual )

    Khurram

  2. #2
    Join Date
    Dec 2002
    Location
    Antwerp, Belgium
    Posts
    227
    i would create a stored procedure in which a declare a variable, lets say vID and then assign it the value of table1_sequence.nextval. Then use the value of vID in your insert statement.
    If you don't use the vID value besides the insert, you can also use the table1_sequence.nextval directly in your sql statement:

    Code:
    insert into 
    table1(col1)
    values(table1_sequence.nextval)
    If you get the table1_sequence after the insert, you are not sure if it's the correct value, because another insert can already have been done.
    Last edited by jora; 11-18-03 at 18:09.
    Johan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •