Get inserted id from mysql insert procedure

北慕城南 提交于 2019-12-25 03:05:28

问题


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.


回答1:


MySQL solution:

After running the insert statement, execute

select last_insert_id() into lastId;

Change your SP to include an OUT parameter as

OUT lastId bigint

or simply run

select last_insert_id();

to return a result set by the SP;

Refer to:

  • MySQL: LAST_INSERT_ID()
    • Value of the AUTOINCREMENT column for the last INSERT


来源:https://stackoverflow.com/questions/22386339/get-inserted-id-from-mysql-insert-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!