postgresql对于各种游标的使用示例
2015-03-13 13:33
676 查看
CREATE OR REPLACE FUNCTION cursor_demo() RETURNS refcursor AS $BODY$ declare unbound_refcursor refcursor; v_id int; v_step_desc varchar(1000); begin open unbound_refcursor for execute 'select id,step_desc from t_runtime_step_log'; loop fetch unbound_refcursor into v_id,v_step_desc; if found then raise notice '%-%',v_id,v_step_desc; 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; CREATE OR REPLACE FUNCTION cursor_demo1(refcursor) RETURNS refcursor AS $$ begin open $1 for select * from t_runtime_step_log; return $1; exception when others then raise exception 'sql exception--%',sqlerrm; end; $$ LANGUAGE plpgsql; begin; select cursor_demo1('a'); fetch all in a; --commit; CREATE OR REPLACE FUNCTION cursor_demo2() RETURNS refcursor AS $$ declare bound_cursor cursor for select * from t_runtime_step_log; begin open bound_cursor; return bound_cursor; end; $$ LANGUAGE plpgsql; begin; select cursor_demo2(); fetch all in bound_cursor; --commit; CREATE OR REPLACE FUNCTION cursor_demo3(p_condition integer) RETURNS refcursor AS $BODY$ declare bound_param_cursor cursor(id_condition integer) for select * from t_runtime_step_log where id > id_condition; begin open bound_param_cursor(p_condition); return bound_param_cursor; end; $BODY$ LANGUAGE plpgsql; begin; select cursor_demo3(5); fetch all in bound_param_cursor; --commit; CREATE OR REPLACE FUNCTION cursor_demo4(p_condition integer) RETURNS refcursor AS $$ declare bound_param_cursor cursor for select * from t_runtime_step_log where id > p_condition; begin open bound_param_cursor; return bound_param_cursor; end; $$ LANGUAGE plpgsql; begin; select cursor_demo4(5); fetch all in bound_param_cursor; --commit;
相关文章推荐
- Sql Server 2000 中游标的使用示例
- 在Oralce存储过程中使用游标来逐行处理数据示例并执行调试
- oracle中游标的使用,示例
- PostgreSQL游标示例(创建游标,并在函数中遍历之)
- PostgreSQL游标使用举例
- 各种联接的使用示例
- 对于存储过程中表名是变量的游标使用
- SQL 游标 contact_cursor 使用示例
- 创建数据库、表、主外键、各种约束、存储过程、视图、索引、事务使用、触发器、创建登录账号、数据库用户 Sql语句示例
- 各种联接的使用示例.sql
- 各种连接的使用示例
- SQL 游标使用的小例子,对于每行数据根据参数的不同进行Insert或Update操作.
- sql server 2000使用游标和随机查询的脚本示例
- sql循环嵌套、游标使用、循环结果集示例
- MySql 存储过程游标使用示例
- Sql Server 2000 中游标的使用示例 [ZT]
- [MSSQL]存储过程示例(拷贝数据表--游标使用--更新数据-日期函数的使用)
- oracle游标使用示例
- Sql常见问题总结二(Sql语句怎么样查询IP,游标去重复,各种函数使用,各种取时间格式,字符串精确排序,超时锁问题)
- Sql常见问题总结二(Sql语句怎么样查询IP,游标去重复,各种函数使用,各种取时间格式,字符串精确排序,超时锁问题)