MYSQL 使用双引号和单引号时截断了不正确的 DOUBLE
MYSQL Truncated incorrect DOUBLE while using double and single quotation marks
我创建了一个触发器,它在 table 中插入一行,然后在另一个 table 中删除一行。
这是我的触发器
CREATE TRIGGER trigger_delete_log_animal AFTER delete ON animal
FOR EACH ROW
INSERT INTO log_animais (momento, ocorrencia)
VALUES (now(), "The register '" + old.nome_animal + "' was deleted from the animal table");
我希望nome_animal在单引号之间。
但是当我从动物中删除一行时出现以下错误table:
Error Code: 1292. Truncated incorrect DOUBLE value: 'The register ''
我试过将其更改为
'The register "' + old.nome_animal + '" was deleted from the animal table'
还有
"The register \'" + old.nome_animal + "\' was deleted from the animal table"
但是不行
我做错了什么?
不要尝试在 SQL 代码中使用 + 构建字符串。
改用CONCAT():
VALUES (now(), CONCAT(
'The register \'',
old.nome_animal,
'\' was deleted from the animal table'));
然后,使用 \
.
转义字符串中的 '
个字符
'Mrs. O\'Leary\'s cow.'
我创建了一个触发器,它在 table 中插入一行,然后在另一个 table 中删除一行。
这是我的触发器
CREATE TRIGGER trigger_delete_log_animal AFTER delete ON animal
FOR EACH ROW
INSERT INTO log_animais (momento, ocorrencia)
VALUES (now(), "The register '" + old.nome_animal + "' was deleted from the animal table");
我希望nome_animal在单引号之间。
但是当我从动物中删除一行时出现以下错误table:
Error Code: 1292. Truncated incorrect DOUBLE value: 'The register ''
我试过将其更改为
'The register "' + old.nome_animal + '" was deleted from the animal table'
还有
"The register \'" + old.nome_animal + "\' was deleted from the animal table"
但是不行
我做错了什么?
不要尝试在 SQL 代码中使用 + 构建字符串。
改用CONCAT():
VALUES (now(), CONCAT(
'The register \'',
old.nome_animal,
'\' was deleted from the animal table'));
然后,使用 \
.
'
个字符
'Mrs. O\'Leary\'s cow.'