我有一个名为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
答案 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;
如果查询结果返回多行,则会失败。如果要使用循环,则需要设置游标。