-1
我传递一个类型创建一个存储过程,做一个循环的过程中,这样我可以将每个信息类型环
这是我喜欢的类型
create type leketo as(id integer, name text);
功能将行插入我喜欢的类型
CREATE OR REPLACE FUNCTION getLeketo()
RETURNS SETOF leketo AS
$BODY$
declare
l leketo;
begin
l.id := 1;
l.name := 'One';
return next l;
l.id := 2;
l.name := 'Two';
return next l;
l.id := 3;
l.name := 'Three';
return next l;
l.id := 4;
l.name := 'Four';
return next l;
l.id := 5;
l.name := 'Five';
return next l;
end
$BODY$
LANGUAGE plpgsql VOLATILE;
运行函数返回这样对我
select * from getLeketo()
1 One
2 Two
3 Three
4 Four
5 Five
在此过程中,我们将通过所有的行
CREATE OR REPLACE FUNCTION loopLeketo(pl leketo)
RETURNS void AS
$BODY$
declare
l leketo;
begin
for l in (select * from pl) loop
raise notice '----------------------------------------';
raise notice 'id=%, name=%', l.id, l.name;
end loop;
end
$BODY$
LANGUAGE plpgsql VOLATILE;
如果我试试这个,我得到了以下信息
DO $$
declare
l leketo;
begin
select * from getLeketo() into l;
PERFORM loopLeketo(l);
end$$;
错误:关系“PL”不存在