gpt4 book ai didi

mysql - 我在调用另一个存储过程时遇到困难

转载 作者:行者123 更新时间:2023-11-29 09:34:30 25 4
gpt4 key购买 nike

我想在另一个存储过程中调用一个存储过程,但语法似乎不正确。

我尝试跳过该过程并直接执行选择命令,但这似乎不起作用,而且我想知道如何执行此操作。

DELIMITER //
create procedure Find_Eid(Pid int)
select EId from Employees inner join Patient on EId = EId_fk where Patient.PId = Pid;
//
DELIMITER ;
call Find_Eid(4);
drop procedure Fill_Interact;
DELIMITER //
create procedure Fill_Interact()
begin
declare N1 int;
declare TOT date;
declare Rid int;
declare Pid int;
declare Eid int;
set N1 = (select count(*) from Patient);
set TOT = curdate();
set Rid = 1;
set Pid = 1;
while N1 > 0 do
set Eid = (call Find_Eid(Pid));
insert into Interact
(Time_Of_Treatment, RId_fk, PId_fk, EId_fk)
values
(TOT,Rid,Pid, Eid);
if Rid = (select count(*) from Room limit 1) then
set Rid = 1;
set TOT = TOT + 1;
else
set Rid = Rid + 1;
end if;
set N1 = N1 - 1;
set Pid = Pid + 1;
end while;
end;
//
DELIMITER ;
call Fill_Interact();

select * from Interact;

最佳答案

如果要将过程值分配给另一个变量,则必须在过程中使用输出参数。所以你的第一个过程应该是 -

DELIMITER //
create procedure Find_Eid(in Pid int, out eid int)
select EId into eid
from Employees
inner join Patient on EId = EId_fk
where Patient.PId = Pid;
//

然后您可以在第二个过程中使用此过程 -

drop procedure Fill_Interact;
DELIMITER //
create procedure Fill_Interact()
begin
declare N1 int;
declare TOT date;
declare Rid int;
declare Pid int;
declare Eid int;
set N1 = (select count(*) from Patient);
set TOT = curdate();
set Rid = 1;
set Pid = 1;
while N1 > 0 do
call Find_Eid(Pid, Eid);
insert into Interact
(Time_Of_Treatment, RId_fk, PId_fk, EId_fk)
values
(TOT,Rid,Pid, Eid);
if Rid = (select count(*) from Room) then
set Rid = 1;
set TOT = TOT + 1;
else
set Rid = Rid + 1;
end if;
set N1 = N1 - 1;
set Pid = Pid + 1;
end while;
end;
//
DELIMITER ;
call Fill_Interact();

关于mysql - 我在调用另一个存储过程时遇到困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57962423/

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