Inserting into Oracle and retrieving the generated sequence ID

后端 未结 5 2068
既然无缘
既然无缘 2020-12-01 03:08

I have a handful of raw SQL queries for SQL Server which use SCOPE_IDENTITY to retrieve the generated ID for a specific INSERT immediately after that INSERT occurs all in on

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 03:22

    There are no auto incrementing features in Oracle for a column. You need to create a SEQUENCE object. You can use the sequence like:

    insert into table(batch_id, ...) values(my_sequence.nextval, ...)
    

    ...to return the next number. To find out the last created sequence nr (in your session), you would use:

    my_sequence.currval
    

    This site has several complete examples on how to use sequences.

提交回复
热议问题