Oracle触发日期

时间:2014-04-28 12:44:03

标签: sql oracle triggers

CREATE OR REPLACE TRIGGER CRIMEDATE
    BEFORE INSERT or UPDATE of DATE_CLOSED
    ON CRIME
    for each row
    declare :new.date_closed

BEGIN

   if (:new.date_closed < crime_date) then raise_application_error(-20002, 'Date Closed must be after crime date');
   end if;
END;

我正在尝试创建一个触发器,如果​​为date_closed输入的日期早于实际犯罪日期,则会触发该触发器,但我仍然会遇到以下错误:

    Error at line 1: PLS-00103: Encountered the symbol "" when expecting one of the 
    following: begin function pragma procedure subtype type <an identifier> <a double-quoted 
    -identifier> current cursor delete exists prior The symbol "" was ignored. 0.06 seconds

我已经尝试了很长时间才能弄明白,任何人都可以帮忙吗?谢谢

1 个答案:

答案 0 :(得分:1)

试试这个:

CREATE OR REPLACE TRIGGER CRIMEDATE
    BEFORE INSERT or UPDATE of DATE_CLOSED
    ON CRIME
    FOR EACH ROW
BEGIN
   IF (:new.date_closed < :new.crime_date)  THEN
      raise_application_error(-20002, 'Date Closed must be after crime date');
   END IF;
END;