oracle 获取oracle db中最后插入记录的ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3131064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:40:12  来源:igfitidea点击:

Get ID of last inserted record in oracle db

oracle

提问by haymansfield

I want to retrieve the id of a newly inserted record with an auto incrementing id column (using the sequence and trigger method). What is the standard way to do this?

我想用自动递增的 id 列(使用序列和触发器方法)检索新插入记录的 id。执行此操作的标准方法是什么?

回答by Tony Andrews

Use the PL/SQL RETURNINGclause:

使用 PL/SQLRETURNING子句:

insert into mytable (...) values (...)
returning id into v_id;