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=# 
复制代码





目录
相关文章
|
4月前
|
SQL 关系型数据库 MySQL
Greenplum【SQL 02】ROW_NUMBER编号函数使用方法举例
Greenplum【SQL 02】ROW_NUMBER编号函数使用方法举例
58 0
|
存储 Oracle 关系型数据库
Oracle行转列函数PRINT_TABLE的用法
Oracle行转列函数PRINT_TABLE的用法
91 0
|
SQL Go 数据库
SQL SERVER中用户定义标量函数(scalar user defined function)的性能问题
原文:SQL SERVER中用户定义标量函数(scalar user defined function)的性能问题 用户定义函数(UDF)分类       SQL SERVER中的用户定义函数(User Defined Functions 简称UDF)分为标量函数(Scalar-Valued Function)和表值函数(Table-Valued Function)。
1218 0
|
存储 SQL
SQL得到任意一个存储过程的参数列表sp_procedure_params_rowset
SQL得到任意一个存储过程的参数列表sp_procedure_params_rowsetexec sp_procedure_params_rowset 'up_rpt营业收入汇总表' PROCEDURE_CATALOG PROCEDURE_SCHEMA PROCEDURE...
1049 0
|
关系型数据库 Perl