Oracle SQL触发器错误:ORA-00933

时间:2016-10-30 16:58:56

标签: sql oracle plsql triggers ora-00933

所以我试图创建一个改变记录时间戳的触发器,到目前为止我有这个

    create or replace TRIGGER job_date_set
      AFTER INSERT OR UPDATE OF start_date, closing_date ON jobs
      FOR EACH ROW
    BEGIN
      IF UPDATING THEN
        CASE
          WHEN :OLD.closing_date != :NEW.closing_date THEN 
            UPDATE jobs
            SET closing_date = to_date(to_date(:NEW.closing_date,'DD/MON/YYYY')||' 23:59:59','DD/MON/YYYY HH24:MI:SS')
            WHERE :OLD.job_id = job_id;
          WHEN :OLD.start_date != :NEW.start_date THEN 
            UPDATE jobs
            SET start_date = to_date(to_date(:NEW.start_date,'DD/MON/YYYY') ||' 00:00:00','DD/MON/YYYY HH24:MI:SS')
            WHERE :OLD.job_id = job_id;
        END CASE;
      END IF;
      IF INSERTING THEN
        UPDATE jobs
        SET closing_date = to_date(to_date(:NEW.closing_date,'DD/MON/YYYY') ||' 23:59:59','DD/MON/YYYY HH24:MI:SS')
        SET start_date = to_date(to_date(:NEW.start_date,'DD/MON/YYYY')||' 00:00:00','DD/MON/YYYY HH24:MI:SS')
        WHERE :OLD.job_id = job_id;   
      END IF;
    END;

以下是错误的描述: 编译失败,第17行(16:54:27)与编译错误关联的行号与第一个BEGIN语句相关。这只会影响数据库触发器的编译。 PL / SQL:ORA-00933:SQL命令未正确结束编译失败,第15行(16:54:27)与编译错误关联的行号与第一个BEGIN语句相关。这只会影响数据库触发器的编译。 PL / SQL:忽略SQL语句

听到它的声音,它并不认为我的if语句已被正确关闭,但我不知道我哪里出错了

2 个答案:

答案 0 :(得分:1)

当您修改表时,触发器已定义,您需要之前的更新触发器。所以,像这样:

create or replace TRIGGER job_date_set
  BEFORE INSERT OR UPDATE OF start_date, closing_date ON jobs
  FOR EACH ROW
BEGIN
  IF UPDATING THEN
    CASE
      WHEN :OLD.closing_date <> :NEW.closing_date THEN 
        SELECT to_date(to_date(:NEW.closing_date,'DD/MON/YYYY')||' 23:59:59','DD/MON/YYYY HH24:MI:SS')
        INTO :NEW.closing_date
        FROM dual;
      WHEN :OLD.start_date <> :NEW.start_date THEN 
        SELECT to_date(to_date(:NEW.start_date,'DD/MON/YYYY') ||' 00:00:00','DD/MON/YYYY HH24:MI:SS')
        INTO :NEW.start_date
        FROM dual;
    END CASE;
  END IF;
  IF INSERTING THEN
    SELECT to_date(to_date(:NEW.closing_date,'DD/MON/YYYY') ||' 23:59:59','DD/MON/YYYY HH24:MI:SS'),
           to_date(to_date(:NEW.start_date,'DD/MON/YYYY')||' 00:00:00','DD/MON/YYYY HH24:MI:SS')
    INTO :NEW.closing_date, :NEW.start_date;
  END IF;
END;

答案 1 :(得分:1)

而不是:

    UPDATE jobs
    SET closing_date = to_date(to_date(:NEW.closing_date,'DD/MON/YYYY') ||' 23:59:59','DD/MON/YYYY HH24:MI:SS')
    SET start_date = to_date(to_date(:NEW.start_date,'DD/MON/YYYY')||' 00:00:00','DD/MON/YYYY HH24:MI:SS')
    WHERE :OLD.job_id = job_id;   

它是:

    UPDATE jobs
    SET closing_date = to_date(to_date(:NEW.closing_date,'DD/MON/YYYY') ||' 23:59:59','DD/MON/YYYY HH24:MI:SS'),
        start_date = to_date(to_date(:NEW.start_date,'DD/MON/YYYY')||' 00:00:00','DD/MON/YYYY HH24:MI:SS')
    WHERE :OLD.job_id = job_id;   

即。有一个逗号而不是第二个 SET 关键字。