我讨厌这样做,但我的SQL很弱,我无法使用错误消息进行故障排除来纠正语法。有人可以帮助检查我的语法,看看导致错误的原因是什么?我认为这与DECLARE和BEGIN有关。也许我应该删除声明?
我得到的错误是PLS-00103: Encountered the symbol "INSERT" when expecting one of the following: . ( * @ % & = - + < / > at in is mod remainder not rem then <an exponent (**)> <> or != or ~= >= <= <> and or lik
PLS-00103: Encountered the symbol "UPDATE" when expecting one of the following: . ( * @ % & = - + < / > at in is mod remainder not rem then <an exponent (**)> <> or != or ~= >= <= <> and or lik <BR>
我创建触发器的语法:
create or replace trigger emp_dept_briu
instead of insert or update on emp_dept_v
referencing new as n
old as o
for each row
declare
l_deptno emp.deptno%type;
begin
case
when inserting
insert into emp
( empno, ename , deptno)
values
( :n.empno, :n.ename, :n.deptno )
;
insert into dept
( deptno, dname )
values
( :n.deptno, :n.dname )
;
when updating
update emp
set ename = :n.ename
, deptno = :n.deptno
where empno = :n.empno
;
update dept
set dname = :n.dname
where deptno = :n.deptno
;
else
null
;
end case
;
end
;
答案 0 :(得分:2)
你的语法完全错了。那就是
CASE
WHEN INSERTING THEN
INSERT INTO ...;
INSERT INTO ...;
WHEN UPDATING THEN
UPDATE ...;
ELSE NULL;
END;
但我会建议你去
IF INSERTING THEN
...;
ELSIF UPDATING THEN
...;
ELSE
NULL;
END IF;
答案 1 :(得分:0)
很酷,让它上班。谢谢@nexus。
create or replace trigger emp_dept_briu
instead of insert or update on emp_dept_v
referencing new as n
old as o
for each row
declare
l_deptno emp.deptno%type;
begin
CASE
when inserting THEN
insert into emp
( empno, ename , deptno)
values
( :n.empno, :n.ename, :n.deptno )
;
insert into dept
( deptno, dname )
values
( :n.deptno, :n.dname )
;
when updating THEN
update emp
set ename = :n.ename
, deptno = :n.deptno
where empno = :n.empno
;
update dept
set dname = :n.dname
where deptno = :n.deptno
;
else
null
;
end case;
end;