0

我讨厌这样做,但我的 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 
;
4

2 回答 2

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;
于 2018-01-31T03:06:27.457 回答
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;
于 2018-01-31T18:03:53.303 回答