简体   繁体   English

Oracle SQL触发器错误:ORA-00933

[英]Oracle SQL Trigger error: ORA-00933

So I'm trying to create a trigger that alters a records timestamp, I have this so far 所以我试图创建一个触发器来改变记录的时间戳,到目前为止

    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;

Here is the description of the errors: Compilation failed, line 17 (16:54:27) The line numbers associated with compilation errors are relative to the first BEGIN statement. 这里是错误的描述:编译失败,第17行(16:54:27)与编译错误相关的行号是相对于第一个BEGIN语句的。 This only affects the compilation of database triggers. 这仅影响数据库触发器的编译。 PL/SQL: ORA-00933: SQL command not properly endedCompilation failed, line 15 (16:54:27) The line numbers associated with compilation errors are relative to the first BEGIN statement. PL / SQL:ORA-00933:SQL命令未正确结束编译失败,第15行(16:54:27)与编译错误关联的行号是相对于第一个BEGIN语句的。 This only affects the compilation of database triggers. 这仅影响数据库触发器的编译。 PL/SQL: SQL Statement ignored PL / SQL:忽略了SQL语句

By the sounds of it, it doesn't think my if statement has been closed properly, but I have no idea where I've gone wrong 从它的声音来看,它认为我的if语句未正确关闭,但是我不知道我哪里出错了

When you are modifying the table the trigger is defined on, you want a before update trigger. 在修改定义触发器的表时,您需要一个更新触发器。 So, something like this: 因此,如下所示:

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;

Instead of: 代替:

    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;   

it's: 它的:

    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;   

Ie there is a comma instead of the second SET keyword. 即有一个逗号而不是第二个SET关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM