为type指定默认值

时间:2013-10-16 16:43:18

标签: oracle postgresql user-defined-functions postgresql-9.2 optional-parameters

如何将以下类型的Oracle语句的默认值分配到PostgreSQL 9.3中?

CREATE OR REPLACE FUNCTION(....
...
DECLARE
 v_var Table01.column01%TYPE := 'SLOW';
BEGIN
...
...
END;

1 个答案:

答案 0 :(得分:1)

Postgres允许提供参数默认值,这会在函数调用中输入缺少的参数。仅允许列表末尾的参数 例如:

CREATE OR REPLACE FUNCTION foo (
                  param1 int
                , v_char tbl01.col01%TYPE DEFAULT 'foo')
...
-- no need to DECLARE anything else.
BEGIN
...

语法快捷方式为v_char tbl01.col01%TYPE = 'foo'

呼叫:

SELECT * FROM foo(1, 'bar');
SELECT * FROM foo(1);        -- Param default kicks in

Details in the manual.