create or replace trigger article_log_file
after update or delete or insert
on article
for each row
begin
   if updating then
      insert into log_file values
(old.authorID,'update',old.artcleName,sysdate);   else if deleting then
      insert into log_file values
(old.authorID,'delete',old.artcleName,sysdate);
  
    else if inserting then
      insert into log_file values
(new.authorID,'insert',new.artcleName,sysdate);
     end if;
end;虽然语句执行了,但编译器提示编译带有错误,而且我插入时也出现了错误,望指教,初学……

解决方案 »

  1.   

    我数了下,end if 只有一个,if 却有3个。if 要与 end if 匹配
      

  2.   

    else if 改为 elsif 试试PL/SQL if语句语法
    if <条件1> then
       <语句1>;
    elsif <条件2> then
       <语句2>;
    elsif <语句3> then
       ....
    else
       <语句n>;
    end if;
      

  3.   

    create or replace trigger article_log_file
    after update or delete or insert
    on article
    for each row
    begin
       if updating then
          insert into log_file values
    (old.authorID,'update',old.artcleName,sysdate);   elseif deleting then
          insert into log_file values
    (old.authorID,'delete',old.artcleName,sysdate);
      
        else
          insert into log_file values
    (new.authorID,'insert',new.artcleName,sysdate);
       end if;
    end;
      

  4.   


    create or replace trigger article_log_file
    after update or delete or insert
    on article
    for each row
    begin
       if updating then
          insert into log_file values
    (old.authorID,'update',old.artcleName,sysdate);   elsif deleting then
          insert into log_file values
    (old.authorID,'delete',old.artcleName,sysdate);
      
        elsif inserting then
          insert into log_file values
    (new.authorID,'insert',new.artcleName,sysdate);
         end if;
    commit;---要提交下
    end;--把else if 改成elsif
      

  5.   

    CREATE TABLE article(
    authorID NUMBER(18,0),
    artcleName VARCHAR2(30),
    cdate DATE DEFAULT SYSDATE);
    CREATE TABLE log_file(
    authorID NUMBER(18,0),
    optype VARCHAR2(10),
    artcleName VARCHAR2(30),
    cdate DATE );CREATE OR REPLACE TRIGGER article_log_file
    BEFORE INSERT OR UPDATE OR DELETE ON article
    FOR EACH ROW
    BEGIN
      IF UPDATING THEN
        insert into log_file values(:old.authorID,'update',:old.artcleName,sysdate);
      ELSIF DELETING THEN
        insert into log_file values(:old.authorID,'delete',:old.artcleName,sysdate);
      ELSIF INSERTING THEN
        insert into log_file values(:new.authorID,'insert',:new.artcleName,sysdate);
      END IF;
      COMMIT;
    END;
    /
      

  6.   

    CREATE OR REPLACE TRIGGER article_log_file
    BEFORE INSERT OR UPDATE OR DELETE ON article
    FOR EACH ROW
    BEGIN
      IF UPDATING THEN
        insert into log_file values(:old.authorID,'update',:old.artcleName,sysdate);
      ELSIF DELETING THEN
        insert into log_file values(:old.authorID,'delete',:old.artcleName,sysdate);
      ELSIF INSERTING THEN
        insert into log_file values(:new.authorID,'insert',:new.artcleName,sysdate);
      END IF;
    END;
    /-- 去掉最后的commit
      

  7.   

    CREATE TABLE article(
    authorID NUMBER(18,0),
    artcleName VARCHAR2(30),
    cdate DATE DEFAULT SYSDATE);
    CREATE TABLE log_file(
    authorID NUMBER(18,0),
    optype VARCHAR2(10),
    artcleName VARCHAR2(30),
    cdate DATE );CREATE OR REPLACE TRIGGER article_log_file
    BEFORE INSERT OR UPDATE OR DELETE ON article
    FOR EACH ROW
    BEGIN
      IF UPDATING THEN
        insert into log_file values(:old.authorID,'update',:old.artcleName,sysdate);
      ELSIF DELETING THEN
        insert into log_file values(:old.authorID,'delete',:old.artcleName,sysdate);
      ELSIF INSERTING THEN
        insert into log_file values(:new.authorID,'insert',:new.artcleName,sysdate);
      END IF;
    END;
    /insert into article(authorid, artcleName, cdate) values(1,'luoyoumou',sysdate);insert into article(authorid, artcleName, cdate) values(2,'huajianguo',sysdate); -- 若此操作回滚,在log_file表中将无相应的日志记录行update article set artclename='hanchaoyong' where authorid=2;select * from article;
    select * from log_file;--------------- 最好做成自治事务触发器,这样不管你在article表上作的DELETE、UPDATE、INSERT操作是否回滚,log_file表中都将有其相应的日志记录行!
    CREATE OR REPLACE TRIGGER article_log_file
    BEFORE INSERT OR UPDATE OR DELETE ON article
    FOR EACH ROW
    DECLARE
      PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
      IF UPDATING THEN
        insert into log_file values(:old.authorID,'update',:old.artcleName,sysdate);
      ELSIF DELETING THEN
        insert into log_file values(:old.authorID,'delete',:old.artcleName,sysdate);
      ELSIF INSERTING THEN
        insert into log_file values(:new.authorID,'insert',:new.artcleName,sysdate);
      END IF;
      COMMIT; -- commit语句可以放在自治事务触发器中,但不能放在普通触发器中!
    END;
    /
      

  8.   


    create or replace trigger article_log_file
    after update or delete or insert
    on article
    for each row
    begin
       if updating then
          insert into log_file values
    (:old.authorID,'update',:old.artcleName,sysdate);   elsif deleting then
          insert into log_file values
    (:old.authorID,'delete',:old.artcleName,sysdate);
      
        elsif inserting then
          insert into log_file values
    (:new.authorID,'insert',:new.artcleName,sysdate);
         end if;
    commit;---要提交下
    end;--把else if 改成elsif
    --没看清你的 修改了下  插入老数据或者新的要在是这样的格式:old.col,:new.col