mysql触发器中的语法错误

时间:2012-03-20 03:02:29

标签: mysql sql triggers

我试图弄清楚这个触发器有什么问题。我是mysql触发器和存储过程的新手,所以我想语法可能有问题。

-- Trigger DDL Statements
DELIMITER $$

USE `SNPB`$$

DROP TRIGGER IF EXISTS getMsnps$$
CREATE TRIGGER getMsnps AFTER INSERT ON m_snps
FOR EACH ROW 
BEGIN

    DECLARE glid int(10);
    DECLARE lost int(1);
    DECLARE st int(10);
    DECLARE vto varchar(20);

    IF(EXISTS( SELECT glyc_id  FROM glyc WHERE glyc_start<=NEW.uni_pos AND glyc_end>=NEW.uni_pos AND glyc.uni_prot_ac=NEW.uni_prot_ac)) THEN
    SELECT glyc_id,glyc_start INTO glid,st  FROM glyc WHERE glyc_start<=NEW.uni_pos AND glyc_end>=NEW.uni_pos AND glyc.uni_prot_ac=NEW.uni_prot_ac;    
    SELECT all_snps.var_to INTO vto FROM all_snps,snp_map WHERE snp_map.snpb_id=NEW.snpb_id AND snp_map.ref>0 AND snp_map.all_snps_id=all_snp.all_snps_id;
    set lost=0;     
    IF NEW.uni_pos=st AND vto!='n' AND vto!='N' THEN
        set lost=1;
    END IF;
    IF NEW.uni_pos=st+1 AND (vto='p' OR vto='P') THEN
        set lost=1;
    END IF;
    IF NEW.uni_pos=st+2 AND vto!='s' AND vto!='S' AND vto!='t' AND vto!='T' THEN
        set lost=1;
    END IF;
    INSERT INTO glyc_map (glyc_id,snpb_id,loss)  VALUES (glid,NEW.snpb_id,lost);

END IF;  
END;
$$
DELIMITER ;

因此,当我在表“m_snps”上插入行时(单个语句插入多行)我应该在“glyc_map”表中获得一些行,但这种情况从未发生过。我希望有人能告诉我语法是对还是错。

1 个答案:

答案 0 :(得分:0)

您的所有代码都在IF

IF(EXISTS( SELECT glyc_id  FROM glyc ...
    -- rest of code, including the insert statement
END IF;

如果条件为假,你什么都不会发生。