PL/pgSQL多输出参数例子

例子一,不带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=# 

 

posted @ 2013-07-14 19:03  健哥的数据花园  阅读(790)  评论(0编辑  收藏  举报