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 for select * from t_runtime_step_log; return ;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;总结
以上是内存溢出为你收集整理的postgresql对于各种游标的使用示例全部内容,希望文章能够帮你解决postgresql对于各种游标的使用示例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)