这些触发错误意味着什么

时间:2014-12-01 23:49:04

标签: sql database oracle triggers

嘿,伙计们先谢谢你的帮助。我现在遇到了一个新问题。在我的作业后几步,我需要为此触发器添加一个额外的部分。触发器需要从副本数中减去一个。当份数达到0时,它应显示不可用。我一直在努力寻找最后几个小时,这就是我想出来的。任何帮助或建议将不胜感激!!

CREATE or REPLACE Trigger Unavailable_Rule
 BEFORE INSERT ON Transaction
 FOR EACH ROW

BEGIN


IF :new.Date_Rented_Out  is not null AND :new.Date_Returned is NULL AND Num_Copies=1 
 THEN 
   UPDATE Video
   set Num_Copies = Num_Copies - 1,
    Status = 'Unavailable'
   where Vid_Num = :new.Vid_Num;

ELSE

 Num_Copies = Num_Copies - 1;
 End IF;
 END;
/
show errors;

6/4  PL/SQL: SQL Statement ignored  
7/15  PL/SQL: ORA-00971: missing SET keyword  
13/13  PLS-00103: Encountered the symbol "=" when expecting one of the f ollowing: := . ( @ % ;  
14/2  PLS-00103: Encountered the symbol "END"  

1 个答案:

答案 0 :(得分:1)

您的update声明错误。而不是:

UPDATE Video
   Num_Copies = Num_Copies -1
   set Status = 'Unavailable'
where Vid_Num = :new.Vid_Num;

Num_Copies

中分配set
UPDATE Video
   set Num_Copies = Num_Copies - 1,
       Status = 'Unavailable'
   where Vid_Num = :new.Vid_Num;

编辑:

您的if声明可以替换为:

UPDATE Video
    set Num_Copies = Num_Copies - 1,
        Status = (case when :new.Date_Rented_Out  is not null AND :new.Date_Returned is NULL AND Num_Copies = 1 then 'Unavailable'
                       else status
                  end)
    where Vid_Num = :new.Vid_Num;