Assigning default value for type

不问归期 提交于 2019-12-13 00:25:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!