一个 psql 函数 (sp_some_function) 返回 2 个游标:
create or replace function sp_some_function() RETURNS SETOF REFCURSOR
as
$BODY$
declare
c_one refcursor := 'one' ;
c_two refcursor := 'two' ;
begin
open c_one for
select *
from TABLE_1;
return next c_one ;
open c_two for
select *
from TABLE_2;
return next c_two ;
return;
end
$BODY$
LANGUAGE PLPGSQL
我想看看 2 个游标中的每一个“包含”什么数据。
为此,我编写了以下脚本:
DO $$
BEGIN
select sp_some_function();
FETCH ALL IN "one";
FETCH ALL IN "two";
END;
$$;
运行脚本会导致以下错误消息:
ERROR: "one" is not a known variable
我还尝试了以下方法:
DO $$
BEGIN
select sp_some_function();
FETCH ALL IN c_one;
FETCH ALL IN c_two;
END;
$$;
这导致以下错误消息:
ERROR: c_one is not a known variable
最后,我尝试了以下方法:
create or replace function sp_some_function() RETURNS SETOF REFCURSOR
as
$BODY$
declare
c_one refcursor := 'one' ;
c_two refcursor := 'two' ;
begin
open c_one for
select *
from TABLE_1;
FETCH ALL IN c_one;
return next c_one ;
open c_two for
select *
from TABLE_2;
FETCH ALL IN c_two;
return next c_two ;
return;
end
$BODY$
LANGUAGE PLPGSQL
这也不起作用。
...我怎样才能得到两个游标的内容?