中国领先的会员管理系统,微卡通会员管理系统,联系QQ:36281733

asp.net ext vc++ gamehack asm vb

天下武功,唯快不破.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

postgresql 游标,函数,存储过程使用例子

Posted on 2018-02-03 15:25  很聪明的Joy  阅读(10488)  评论(0编辑  收藏  举报
CREATE OR REPLACE FUNCTION cursor_demo()  
  RETURNS refcursor AS  --返回一个游标
$BODY$  
declare  --定义变量及游标
    unbound_refcursor refcursor;  --游标
    t_accid varchar;    --变量
        t_accid2 int;    --变量

begin  --函数开始
    open unbound_refcursor for execute 'select name from cities_bak';  --打开游标 并注入要搜索的字段的记录
    loop  --开始循环
        fetch unbound_refcursor into t_accid;  --将游标指定的值赋值给变量
          
        if found then  --任意的逻辑
            raise notice '%-',t_accid;  
        else  
            exit;  
        end if;  
    end loop;  --结束循环
    close unbound_refcursor;  --关闭游标
    raise notice 'the end of msg...';  --打印消息
    return unbound_refcursor; --为函数返回一个游标
exception when others then  --抛出异常
    raise exception 'error-----(%)',sqlerrm;--字符“%”是后面要显示的数据的占位符
end;  --结束
$BODY$  

  LANGUAGE plpgsql;  --规定语言

 

select cursor_demo(); --调用

 

中国领先的会员管理系统,微卡通会员管理系统,联系QQ:36281733