【发布时间】:2015-10-29 13:07:30
【问题描述】:
我正在尝试遍历游标(plpgsql)结果,但不知何故,输出控制台上没有打印任何内容。
create or replace function curs() returns refcursor as
$body$
declare
curs cursor for select id from stores;
store stores.id%TYPE;
begin
open curs;
fetch curs into store;
loop
exit when not found;
raise notice 'Value: %',store;
end loop;
close curs;
end
$body$ language plpgsql;
select curs();
如何实现正确的循环?
数据库版本:9.0 表 stores 列 id,name
【问题讨论】:
-
此问题还应提供表定义和您的 Postgres 版本。
-
@ErwinBrandstetter 更新了问题
-
但这不是表定义。表定义是一个完整的
CREATE TABLE脚本,显示数据类型和约束,或者你在 psql 中使用\d tbl得到的结果。
标签: database postgresql stored-procedures cursor plpgsql