有人可以告诉我如何在Oracle中删除程序,但它是否存在?
DROP PROCEDURE IF EXISTS XYZ;
以上不起作用。
答案 0 :(得分:8)
如果您的目标是消除脚本中的错误消息,那么您可以尝试
begin
execute immediate 'drop procedure xyz';
exception when others then
if sqlcode != -4043 then
raise;
end if;
end;
/
答案 1 :(得分:2)
您还可以在以下情况之前查看字典视图:
SELECT * FROM USER_PROCEDURES WHERE PROCEDURE_NAME = 'XYZ'
答案 2 :(得分:1)
我的解决方案:
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;
/
答案 3 :(得分:1)
一个完整的例子:
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;