gpt4 book ai didi

mysql - SQL 触发器未执行...做错了什么?

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

我有这个:

这是之前在 chars_insert 上的内容。

BEGIN
IF EXISTS (SELECT * FROM chars WHERE accid = NEW.accid)
BEGIN
INSERT INTO `char_vars` SET `charid = NEW.charid, `varname` = `NotFirstChar`, `value` = 1;
END

INSERT INTO `char_equip` SET `charid` = NEW.charid;
INSERT INTO `char_exp` SET `charid` = NEW.charid;
INSERT INTO `char_jobs` SET `charid` = NEW.charid;
INSERT INTO `char_pet` SET `charid` = NEW.charid;
INSERT INTO `char_points` SET `charid` = NEW.charid;
INSERT INTO `char_profile` SET `charid` = NEW.charid;
INSERT INTO `char_storage` SET `charid` = NEW.charid;
INSERT INTO `char_inventory` SET `charid` = NEW.charid;
END

我刚刚添加了 IF EXISTS 部分...这打破了触发器。我试图查找一个 accountid 是否已经有一个字符,如果有,则向创建的字符添加一个变量,表示这不是他们的第一个字符。它说错误出现在 IF EXISTS 行,但我没有看到错误...请帮忙?

最佳答案

尝试按以下方式更改 MySQL 的代码:

BEGIN
IF EXISTS (SELECT * FROM chars WHERE accid = NEW.accid) THEN
INSERT INTO `char_vars` SET `charid` = NEW.charid, `varname` = `NotFirstChar`, `value` = 1;
END IF;

INSERT INTO `char_equip` SET `charid` = NEW.charid;
INSERT INTO `char_exp` SET `charid` = NEW.charid;
INSERT INTO `char_jobs` SET `charid` = NEW.charid;
INSERT INTO `char_pet` SET `charid` = NEW.charid;
INSERT INTO `char_points` SET `charid` = NEW.charid;
INSERT INTO `char_profile` SET `charid` = NEW.charid;
INSERT INTO `char_storage` SET `charid` = NEW.charid;
INSERT INTO `char_inventory` SET `charid` = NEW.charid;
END

此外,如果您的 NotFirstChars 是一个常量字符串(不是字段名称),您应该更改引号:'NotFirstChars'

关于mysql - SQL 触发器未执行...做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22951255/

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