DROP 仅在存在时触发 (ORACLE)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34151428/
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
DROP trigger only if it exists (ORACLE)
提问by Pratik Soni
I want to dropa existing trigger in ORACLE.
我想删除ORACLE 中的现有触发器。
I do know the drop
query for the trigger in oracle. But wanted to know that how can I check if that trigger is already exists in Oracle DB.
我知道oracle 中drop
的触发器查询。但想知道如何检查该触发器是否已存在于Oracle DB 中。
DROP query:
删除查询:
DROP TRIGGER **TRIGGER_NAME**
回答by a_horse_with_no_name
You need a PL/SQL block with dynamic SQL for this:
为此,您需要一个带有动态 SQL 的 PL/SQL 块:
-- drop the trigger if it exists
declare
l_count integer;
begin
select count(*)
into l_count
from user_triggers
where trigger_name = 'TRIGGER_NAME';
if l_count > 0 then
execute immediate 'drop trigger trigger_name';
end if;
end;
/
-- now create the trigger
create trigger trigger_name
..
begin
end;
/
Note that (unquoted) identifiers are stored in upper case in the Oracle system catalogs. So make sure you use trigger_name = 'TRIGGER_NAME'
, not trigger_name = 'trigger_name'
in the PL/SQL check
请注意,(未加引号的)标识符以大写形式存储在 Oracle 系统目录中。所以请确保您使用trigger_name = 'TRIGGER_NAME'
, 而不是trigger_name = 'trigger_name'
在 PL/SQL 检查中
回答by hinotf
You have two option:
你有两个选择:
1) Check if trigger exists
1) 检查触发器是否存在
SELECT *
FROM user_triggers
WHERE trigger_name = '...'
2) DROP trigger and check for EXCEPTION
2) DROP 触发器并检查 EXCEPTION