如果 DB Oracle 中存在删除过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21911251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:14:59 来源:igfitidea点击:
drop procedure if exists in DB Oracle
提问by Fawi
Can someone tell me how I can drop a PROCEDURE in Oracle, but just if it exists ?
有人可以告诉我如何在 Oracle 中删除 PROCEDURE,但前提是它存在吗?
DROP PROCEDURE IF EXISTS XYZ;
The above does not work.
以上是行不通的。
回答by René Nyffenegger
If your goal is to eliminate error messages in a script, then you can try
如果您的目标是消除脚本中的错误消息,那么您可以尝试
begin
execute immediate 'drop procedure xyz';
exception when others then
if sqlcode != -4043 then
raise;
end if;
end;
/
回答by Wernfried Domscheit
You can also check dictionary view before:
您还可以之前检查字典视图:
SELECT * FROM USER_PROCEDURES WHERE PROCEDURE_NAME = 'XYZ'
回答by Paride Giovacchini
My solution:
我的解决方案:
DECLARE
V_NUM NUMBER;
BEGIN
SELECT COUNT(*)
INTO V_NUM
FROM USER_OBJECTS
WHERE OBJECT_NAME = 'XYZ'
AND OBJECT_TYPE = 'PROCEDURE';
IF V_NUM > 0 THEN
EXECUTE IMMEDIATE 'DROP PROCEDURE XYZ';
DBMS_OUTPUT.PUT_LINE('Dropped');
END IF;
END;
/
回答by Sheen
A complete example:
一个完整的例子:
declare
c int;
begin
select count(*) into c from user_procedures where object_type = 'FUNCTION' and object_name = 'ABC';
if c = 1 then
execute immediate 'DROP FUNCTION ABC';
end if;
end;