问题
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