开发者

Stored Procedures - How to return multiple values after an Insert

开发者 https://www.devze.com 2023-01-25 20:48 出处:网络
I\'m trying to write a Mysql Stored Procedure that returns two values after inserting a r开发者_如何学运维ecord. I want it to return the auto-generated ID and the value of one column. How would I go a

I'm trying to write a Mysql Stored Procedure that returns two values after inserting a r开发者_如何学运维ecord. I want it to return the auto-generated ID and the value of one column. How would I go about doing this? Here's what I got so far:

delimiter //

drop procedure if exists insert_car//
create procedure insert_car(make VARCHAR(20), color VARCHAR(20))
begin
 INSERT INTO table values (make,'2003', color);
 SELECT LAST_INSERT_ID();
end//

delimiter ;


As LAST_INSERT_ID() is a normal function, you can just

SELECT LAST_INSERT_ID(), the_column FROM the_table LIMIT 1;
0

精彩评论

暂无评论...
验证码 换一张
取 消