我正在尝试实现触发器引发用户定义的错误消息,并且不允许在数据库中进行更新和插入操作。我是pl / sql的新手我从互联网上审阅了一些代码并尝试实现。我的代码运行正常,因为我无法更新/插入数据库但仍然无法获取用户定义的消息,而且我收到此警告。
Warning: Trigger created with compilation errors ?
这是表格:
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(5)
NAME VARCHAR2(20)
SALARY NUMBER(10)
DEPOT_ADDRESS VARCHAR2(15)
这是我的代码:
create or replace trigger cleaner_before_update_insert
for update or insert on cleaner
compound trigger
count binary_integer;
before statement is
begin
count:=0;
end before statement;
after each row is
begin
count :=count +1;
end after each row;
after statement is
begin
if count > 0 then
raise_application_error( -20001,'Update/insert operation can not be completed ');
end if;
end after statement;
end cleaner_before_update;
/
任何人都可以帮我弄清楚这里有什么问题以及解决问题的方法。 提前谢谢。
即使在编译代码之后,它也会给我这个错误。
ORA-06512: at "SYSTEM.CLEANER_BEFORE_UPDATE_INSERT", line 18
ORA-04088: error during execution of trigger
'SYSTEM.CLEANER_BEFORE_UPDATE_INSERT'
答案 0 :(得分:0)
TRIGGER
阻止了几个问题。
触发器cleaner_before_update_insert
的名称与最终cleaner_before_update
声明后的end
不匹配。
COUNT
是一个SQL关键字,不允许在PL / SQL中用作变量。您会收到错误 - Error(10,11): PLS-00204: function or pseudo-column 'COUNT' may be used inside a SQL statement only
所以,这是修改后的代码。
CREATE OR REPLACE TRIGGER cleaner_before_update_insert FOR UPDATE OR
INSERT ON cleaner compound TRIGGER
v_count binary_integer;
before STATEMENT
IS
BEGIN
v_count:=0;
END before STATEMENT;
AFTER EACH row
IS
BEGIN
v_count :=v_count +1;
END AFTER EACH row;
AFTER STATEMENT
IS
BEGIN
IF v_count > 0 THEN
raise_application_error( -20001,'Update/insert operation can not be completed ');
END IF;
END AFTER STATEMENT;
END cleaner_before_update_insert;
/