pg>游标及客户端查询
2021-09-26 11:15:16    95    0    0
ivan

创建函数返回游标:

CREATE or REPLACE FUNCTION fun_cursor( in v_p1 int,in v_p2 int, refcursor, refcursor)
RETURNS SETOF refcursor AS $$
    BEGIN
        OPEN $3 FOR SELECT * FROM users where u_type = v_p1;
        RETURN NEXT $3;
        OPEN $4 FOR SELECT * FROM users where u_type = v_p2;
        RETURN NEXT $4;
    END;
$$ LANGUAGE plpgsql;

 客户端调用:
    BEGIN;

        SELECT * FROM fun_cursor(1,2,'a', 'b');

        FETCH ALL FROM a;

        FETCH ALL FROM b;

   COMMIT;

Pre: pg>db2>timestampdiff

Next: pg>mysql>substring_index

95
Sign in to leave a comment.
No Leanote account? Sign up now.
0 comments
Table of content