从MySQL插入过程获取插入的ID [英] Get inserted id from mysql insert procedure
本文介绍了从MySQL插入过程获取插入的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为带有一些输入参数的插入语句创建了一个过程.但是我想从相同的过程中获取插入的ID或插入的行.我使用oracle创建的,效果很好.但是我不知道在mysql中.花更多的时间来做到这一点.我不能.
I create a procedure for insert statement with some input parameters. But i want to get the inserted id or inserted row from the same procedure.I created using oracle, that is working fine. But i don't know in mysql. And spend more time to get this.i can't.
推荐答案
MySQL 解决方案:
运行insert
语句后,执行
select last_insert_id() into lastId;
更改您的SP以将OUT
参数包括为
Change your SP to include an OUT
parameter as
OUT lastId bigint
或简单地运行
select last_insert_id();
返回SP设置的结果;
to return a result set by the SP;
参考:
- MySQL:LAST_INSERT_ID ()
- 最后一次插入的AUTOINCREMENT列的值
- MySQL: LAST_INSERT_ID()
- Value of the AUTOINCREMENT column for the last INSERT
这篇关于从MySQL插入过程获取插入的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文