PL/pgSQL函数带output参数例子

例子1,不带returns :

[postgres@cnrd56 bin]$ ./psql
psql (9.1.2)
Type "help" for help.

postgres=# CREATE FUNCTION sales_tax(subtotal real, OUT tax real) AS $$
postgres$# BEGIN
postgres$#     tax := subtotal * 0.06;
postgres$# END;
postgres$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# 
postgres=# select sales_tax(100);
 sales_tax 
-----------
         6
(1 row)

例子2,带returns:

[postgres@cnrd56 bin]$ ./psql
psql (9.1.2)
Type "help" for help.

postgres=# CREATE FUNCTION sales_tax2(subtotal real, OUT tax real) returns real AS $$
postgres$# BEGIN
postgres$#     tax := subtotal * 0.06;
postgres$# END;
postgres$# $$ LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# 
postgres=# select sales_tax2(100);
 sales_tax2 
------------
          6
(1 row)

postgres=# 

 

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