0

私はこれを行うのが嫌いですが、私の SQL は脆弱で、エラー メッセージを使用して構文を修正するトラブルシューティングを行うことができません。誰かが私の構文をチェックして、エラーの原因を調べるのを手伝ってもらえますか? DECLARE と BEGIN に関係があると思います。多分私はDeclareを削除する必要がありますか?

私が得ているエラーは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 に答える