问题
How to assign default value to following type of Oracle statement into PostgreSQL 9.3?
CREATE OR REPLACE FUNCTION(....
...
DECLARE
v_var Table01.column01%TYPE := 'SLOW';
BEGIN
...
...
END;
回答1:
Postgres allows to provide parameter defaults, which kick in for missing parameters in the function call. Only allowed for parameters at the end of the list.
Example:
CREATE OR REPLACE FUNCTION foo (
param1 int
, v_char tbl01.col01%TYPE DEFAULT 'foo')
...
-- no need to DECLARE anything else.
BEGIN
...
Syntactical shortcut would be v_char tbl01.col01%TYPE = 'foo'.
Call:
SELECT * FROM foo(1, 'bar');
SELECT * FROM foo(1); -- Param default kicks in
Details in the manual.
来源:https://stackoverflow.com/questions/19409055/assigning-default-value-for-type