Oracle - return newly inserted key value

前端 未结 3 1409
栀梦
栀梦 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;
    

提交回复
热议问题