postgresql 遍历参数_PostgreSQL游标示例(创建游标,并在函数中遍历之)

本文介绍了如何在PostgreSQL中使用游标进行数据遍历,包括创建游标函数`top100cur`以及如何在函数`from2cur`中遍历指定范围的记录。示例代码展示了打开游标、提取数据以及在特定索引区间返回记录的用法。
摘要由CSDN通过智能技术生成

PostgreSQL游标示例(创建游标,并在函数中遍历之)

--drop function top100cur(refcursor);

create function top100cur(refcursor) returns refcursor as $$

begin

open $1 for select * from person limit 100;

return $1;

end

$$language plpgsql;

----------测试游标---------

-- SELECT top100cur('abc');

-- fetch all from abc;

-- drop function from2cur(refcursor,int,int);

--这是一个返回游标中在一定范围内记录的函数--

create function from2cur(refcursor,int,int)returns setof text as $$

declare--声明一些下标变量

pnam text;

pno text;

index int;

lower int;

upper int;

begin

index:=1;

lower:=$2;

upper:=$3;

fetch $1 into pnam,pno;--必须先fetch一条,否则found为false

while found loop

--只在[lower,upper]区间的记录才返回--

if lower<=index and upper>=index then

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值