SQL:不允许从函数返回结果集

时间:2016-11-15 12:31:19

标签: mysql sql

我有一个名为compare_two_regions的SQL函数,它返回数据类型BIT,我想在名为compare_two_series的函数上调用此函数。 我简化了这个函数,我只想从compare_two_regions函数返回值。我仍然希望在循环中调用compare_two_regions函数,但即使在这个简化的情况下:

DELIMITER $$

create function compare_two_series( serieA varchar(255), serieB varchar(255)) 
returns BIT 
begin
declare result BIT;

/*falta ver*/
SELECT P1.x1,P1.y1,P1.x2,P1.y2,P2.x1,P2.y1,P2.x2,P2.y2
FROM region as P1, region as P2
WHERE P1.region.series_id = serieA AND P2.region.series_id = serieB;

SELECT compare_two_regions(P1.x1,P1.y1,P1.x2,P1.y2,P2.x1,P2.y1,P2.x2,P2.y2) into result;
return result;
end$$
DELIMITER ;

我收到以下错误:Not allowed to return a result set from a function

1 个答案:

答案 0 :(得分:1)

您可以尝试更改此

SELECT P1.x1,P1.y1,P1.x2,P1.y2,P2.x1,P2.y1,P2.x2,P2.y2
FROM region as P1, region as P2
WHERE P1.region.series_id = serieA AND P2.region.series_id = serieB;

SELECT compare_two_regions(P1.x1,P1.y1,P1.x2,P1.y2,P2.x1,P2.y1,P2.x2,P2.y2) into result;

到这个

SELECT compare_two_regions(P1.x1,P1.y1,P1.x2,P1.y2,P2.x1,P2.y1,P2.x2,P2.y2) into result
FROM region as P1, region as P2
WHERE P1.region.series_id = serieA AND P2.region.series_id = serieB;

如果查询结果返回多行,则会失败。如果要使用循环,则需要设置游标。