您的位置:首页 > 数据库

PL/pgSQL多输出参数例子

2013-07-14 19:03 190 查看
例子一,不带returns:

postgres=# CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$
postgres$# BEGIN
postgres$#     sum := x + y;
postgres$#     prod := x * y;
postgres$# END;
postgres$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=#
postgres=# select sum_n_product(3,4);
sum_n_product
---------------
(7,12)
(1 row)


例子二,带returns:

postgres=# CREATE FUNCTION sum_n_product2(x int, y int, OUT sum int, OUT prod int) returns record AS $$
postgres$# BEGIN
postgres$#     sum := x + y;
postgres$#     prod := x * y;
postgres$# END;
postgres$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=#
postgres=# select sum_n_product2(3,4);
sum_n_product2
----------------
(7,12)
(1 row)

postgres=#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: