Oracle - return newly inserted key value

前端 未结 3 1432
栀梦
栀梦 2021-02-20 14:07

We have a table 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 we created for the table a

相关标签:
3条回答
  • 2021-02-20 14:33

    I don't know if it works with triggers but the RETURNING clause may be what you're looking for:

    INSERT INTO my_table (col_1, col_2)
      VALUES ('foo', 'bar')
      RETURNING pk_id INTO my_variable;
    
    0 讨论(0)
  • 2021-02-20 14:52

    why not just return the_sequence.currval ?

    0 讨论(0)
  • 2021-02-20 15:00

    I think you are looking for a Callable Statement. Here's javadoc if you are trying to get to it from Java.

    0 讨论(0)
提交回复
热议问题