[OR REPLACE] 更新存储介绍

最近更新时间: 2024-06-12 15:06:00

带OR REPLACE的作用就存储过程存在时则替换的功能,建立存储时不带OR REPLACE关键字, 则遇到函数已经存系统则会报错,如下所示:

postgres=#  select prosrc from pg_proc where proname='proc_1';
             prosrc             
--------------------------------
                               +
 begin                         +
    raise notice 'Hello TBase';+
 end;                          +

(1 row)
postgres=# CREATE OR REPLACE PROCEDURE proc_1() AS
$$
begin
raise notice 'Hello,TBase';
end;
$$
LANGUAGE PLPGSQL;
CREATE PROCEDURE
postgres=# select prosrc from pg_proc where proname='proc_1';
             prosrc              
---------------------------------
                                +
 begin                          +
    raise notice 'Hello,TBase';+
 end;                           +
 (1 row)
postgres=#
postgres=# call proc_1();
NOTICE:  Hello,TBase
CALL
postgres=#

另外也可以写成这样:

postgres=# CREATE OR REPLACE PROCEDURE proc_1() AS
begin
raise notice 'Hello,TBase';
end;
/

即不要$$开始和结束符号,最后使用/结束,这个语法更接近于oralce。