【发布时间】:2016-04-11 20:37:57
【问题描述】:
所以我一直在到处寻找,试图了解如何在存储过程中调用函数,我在这里找到了这个示例:http://forums.mysql.com/read.php?98,175470,175476#msg-175476。
这帮助我构建了调用存储过程的函数,但是我不断收到此错误:
16:17:51 select regionUtilization(1,2) LIMIT 0, 1000 Error Code: 1415. Not allowed to return a result set from a function 0.000 sec
我要做的是调用以下存储过程并访问 OUT 变量。然后将其与输入的比较整数进行比较。
drop procedure if exists select_employeesByRegion_proc;
delimiter //
create procedure select_employeesByRegion_proc
(in search int, out result int)
begin
select t1.emp_id from (
select employees.emp_id from branch
inner join department
on department.br_id = branch.br_id
inner join employees
on employees.dep_id = department.dep_id
where branch.reg_id = search) as t1;
set result:=FOUND_ROWS();
end //
delimiter ;
下面是我目前拥有的功能。
drop function if exists regionUtilization;
delimiter //
create function regionUtilization(search int, compare int)
returns boolean
begin
DECLARE temp int;
call select_employeesByRegion_proc(search, temp);
if temp >= compare then
return true;
else
return false;
end if;
end //
delimiter ;
我还研究了通过计算一个计数和另一个返回结果将存储过程的两个方面分离为单独的过程,但是这仍然首先需要过程选择一些会导致相同错误的数据我已经收到了。
关于如何解决结果集错误的任何建议?我没有返回结果集,我只是使用该结果集来选择在我的函数中是返回 true 还是 false。提前致谢!
【问题讨论】:
-
该过程应该使用游标来处理查询结果,这样它就不会返回查询结果。
标签: mysql stored-procedures stored-functions