简体   繁体   中英

Syntax error in mysql trigger

Am trying to figure out what is wrong with this trigger. I am new in mysql triggers and stored procedures so I guess there might be something wrong with the syntax.

-- 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 ;

So when I insert rows on the table "m_snps" (multiple rows are inserted by a single statement) I should get some rows in the "glyc_map" table but that never happens. I was hoping if anyone could tell me whether the syntax is right or wrong.

All your code lies within an IF :

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

If the condition is false, you'll get nothing happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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