例子1,不带returns :
[postgres@cnrd56 bin]$ ./psqlpsql (9.1.2)Type "help" for help.postgres=# CREATE FUNCTION sales_tax(subtotal real, OUT tax real) AS $$postgres$# BEGINpostgres$# tax := subtotal * 0.06;postgres$# END;postgres$# $$ LANGUAGE plpgsql;CREATE FUNCTIONpostgres=# postgres=# select sales_tax(100); sales_tax ----------- 6(1 row)
例子2,带returns:
[postgres@cnrd56 bin]$ ./psqlpsql (9.1.2)Type "help" for help.postgres=# CREATE FUNCTION sales_tax2(subtotal real, OUT tax real) returns real AS $$postgres$# BEGINpostgres$# tax := subtotal * 0.06;postgres$# END;postgres$# $$ LANGUAGE plpgsql;CREATE FUNCTIONpostgres=# postgres=# select sales_tax2(100); sales_tax2 ------------ 6(1 row)postgres=#