-- 用 先取出 count(*) 值   , new 前面要加冒号
dwcount int ; 
select  count(*) into dwcount  from t_article 
where cover=:new.cover and content=:new.content ; 
IF dwcount = 0 then 
    INSERT into t_file (url,content) VALUES (new.cover,new.content) ; 
end if ; 

解决方案 »

  1.   

    dwcount int ; 
    select  count(*) into dwcount  from t_article 
    where cover=:new.cover and content=:new.content ; 
    IF dwcount = 0 then 
        INSERT into t_file (url,content) VALUES (:new.cover,:new.content) ; 
    end if ; 
      

  2.   

    错了,错了,刚才按 oracle 的语法写的。
    换成 mysql 的。
    INSERT into t_file (url,content) VALUES (new.cover,new.content)
    where not exists(select * from t_article where cover=new.cover and content=new.content)
        
      

  3.   

    最终代码写成这样CREATE TRIGGER 'tri_article_update' BEFORE UPDATE ON 't_article' 
    FOR EACH ROW
    BEGIN
    INSERT into t_file (url,content) VALUES (new.cover,new.content)
    where NOT EXISTS(select * from t_article where cover=new.cover and content=new.content)
    END
    但是还是报错啊~
      

  4.   

    delimiter $$
    CREATE trigger tri_article_update before UPDATE ON t_article FOR EACH ROW
    BEGIN
        declare cnt int;
        select COUNT(*) into cnt from t_article where cover=new.cover and content=new.content;
        if(cnt=0) then 
        INSERT into t_file (url,content) VALUES (new.cover,new.content);
        end if;
    END$$
      

  5.   

    空是null值,不是0,if要用is null
    CREATE tigger 'tri_article_update' 
    BEFORE UPDATE ON 't_article'
     FOR EACH ROW BEGIN     
     IF (select COUNT(*) from t_article where cover=new.cover and content=new.content) =0 (改为is null)    
    THEN 
    INSERT into t_file (url,content) VALUES (new.cover,new.content) END