gpt4 book ai didi

mysql - mysql触发器语法错误

转载 作者:行者123 更新时间:2023-11-29 01:04:31 25 4
gpt4 key购买 nike

我想弄清楚这个触发器有什么问题。我是 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”表中获得一些行,但这种情况从未发生过。我希望是否有人能告诉我语法是对还是错。

最佳答案

您所有的代码都在 IF 中:

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

如果条件为假,则什么也不会发生。

关于mysql - mysql触发器语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9780825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com