合 PG 14新特性之存储过程支持out参数
Tags: PGPostgreSQL新特性存储过程PG 14
示例
1 2 3 4 5 6 | CREATE PROCEDURE insert_data(a integer, b integer) LANGUAGE SQL AS $$ INSERT INTO tbl VALUES (a); INSERT INTO tbl VALUES (b); $$; |
or
1 2 3 4 5 6 | CREATE PROCEDURE insert_data(a integer, b integer) LANGUAGE SQL BEGIN ATOMIC INSERT INTO tbl VALUES (a); INSERT INTO tbl VALUES (b); END; |
and call like this:
1 | CALL insert_data(1, 2); |
带out参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | CREATE OR REPLACE PROCEDURE pro_out( p_id in integer, p_out out integer) AS $$ BEGIN p_out := p_id+10; END; $$ LANGUAGE plpgsql; -- 调用 DO $$ DECLARE result int; BEGIN CALL pro_out(100,result); RAISE NOTICE '%', result; END $$; |