gpt4 book ai didi

MySql存储过程out id返回null

转载 作者:行者123 更新时间:2023-11-29 16:24:32 25 4
gpt4 key购买 nike

我有一个存储过程,它插入到地址表中,它有 3 个输入参数和 1 个输出参数。如果我调用这个过程,参数为空

CREATE DEFINER=`root`@`localhost` 
PROCEDURE `insert_adress`(
in d varchar(50),
in r varchar(50),
in c varchar(50),
in adress_text varchar(255),
out id int)
BEGIN
declare disc_id int;
declare reg_id int;
declare coun_id int;


if ((select count(*) from district where district.dist like d) <> 0)
then set disc_id := (select id from district where district.dist like d);
else
insert into district(dist) values(d);
set disc_id := (select max(id) from district);
end if;

if ((select count(*) from region where region.reg like r) <> 0)
then set reg_id := (select id from region where region.reg like r);
else
insert into region(reg) values(r);
set reg_id := (select max(id) from region);
end if;

if ((select count(*) from country where country.coun like c) <> 0)
then set coun_id := (select id from country where country.coun like c);
else
insert into country(coun) values(c);
set coun_id := (select max(id) from country);
end if;

insert into adress(district,region,country,adress_text) values(disc_id,reg_id,coun_id,adress_text);
set id := (select max(id) from adress);
END

我称之为:

set @id = 0;
call mustaqil.insert_adress('test1', 'test1', 'test1', 'test1', @id);
select @id;

地区、地区、国家/地区表有“test1”行我除了,out id,disc_id,reg_id,coun_id 应该是数字,但它是空的P.S:存储过程插入行

最佳答案

只需更改 set id := (从地址中选择 max(id));到从地址中选择 max(id) 到 id 中;它应该有效

关于MySql存储过程out id返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54320419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com