MySQL - 查询中的多个 INSERT INTO 语句导致无用的错误消息
MySQL - multiple INSERT INTO statements in query result in useless error message
这两个语句都可以正常工作:
甲:
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
VALUES (
(SELECT id FROM table2 WHERE serial = 0002),
'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
7.50, 7.50, ' -- 201900002'
);
乙:
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
VALUES (
(SELECT id FROM table2 WHERE serial = 0002),
'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
3854.50, 2840.88, ' -- 201900002'
);
现在将它们组合成一个查询:
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
VALUES (
(SELECT id FROM table2 WHERE serial = 0002),
'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
7.50, 7.50, ' -- 201900002'
);
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
VALUES (
(SELECT id FROM table2 WHERE serial = 0002),
'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
3854.50, 2840.88, ' -- 201900002'
);
我在第二条语句的开头得到了无用的通用 MySQL 错误:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'INSERT INTO `table1` (`relationId`, `string1`, `date1`, `date2`,
`string2' at line 10
我在这里错过了什么?问题在哪里?我很确定几个月前我使用了相同的脚本来生成查询并且它 运行 正确。
更新:
正如(现已丢失的)评论中所建议的,这可以被 t运行sformed 为 INSERT ... SELECT 语句。所以我尝试了一下,但是 运行 遇到了完全相同的问题。单个 INSERT 验证,连续的 INSERT 抛出 UMEM™(无用 MySQL 错误消息):
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
SELECT id, 'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
7.50, 7.50, ' -- 201900002' FROM table2 WHERE serial = 0002;
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
SELECT id, 'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
7.50, 7.50, ' -- 201900002' FROM table2 WHERE serial = 0002;
所以,这是 st运行ge。
a) 我的实际错误:
源电子表格在第 516 行包含格式错误的数字,导致 excel #VALUE!
错误进入我生成的 SQL 应该是 DECIMAL 值的地方。 MySQL 在第 9 行指出错误并没有真正帮助我在第 5000 行附近找到问题。
b) 在线验证者:
为什么即使语句中没有错误值,在线验证器也会出现完全相同的错误仍然是个谜。事实上,他们现在仍然在完全相同的 SQL 上抛出错误,而在服务器上 运行 正确。
这两个语句都可以正常工作:
甲:
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
VALUES (
(SELECT id FROM table2 WHERE serial = 0002),
'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
7.50, 7.50, ' -- 201900002'
);
乙:
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
VALUES (
(SELECT id FROM table2 WHERE serial = 0002),
'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
3854.50, 2840.88, ' -- 201900002'
);
现在将它们组合成一个查询:
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
VALUES (
(SELECT id FROM table2 WHERE serial = 0002),
'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
7.50, 7.50, ' -- 201900002'
);
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
VALUES (
(SELECT id FROM table2 WHERE serial = 0002),
'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
3854.50, 2840.88, ' -- 201900002'
);
我在第二条语句的开头得到了无用的通用 MySQL 错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO `table1` (`relationId`, `string1`, `date1`, `date2`, `string2' at line 10
我在这里错过了什么?问题在哪里?我很确定几个月前我使用了相同的脚本来生成查询并且它 运行 正确。
更新:
正如(现已丢失的)评论中所建议的,这可以被 t运行sformed 为 INSERT ... SELECT 语句。所以我尝试了一下,但是 运行 遇到了完全相同的问题。单个 INSERT 验证,连续的 INSERT 抛出 UMEM™(无用 MySQL 错误消息):
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
SELECT id, 'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
7.50, 7.50, ' -- 201900002' FROM table2 WHERE serial = 0002;
INSERT INTO `table1`
(`relationId`,
`string1`, `date1`, `date2`, `string2`,
`decimal1`, `decimal2`, `string3`)
SELECT id, 'UNK', '2019-02-27', '2019-03-14', 'ABCDEF',
7.50, 7.50, ' -- 201900002' FROM table2 WHERE serial = 0002;
所以,这是 st运行ge。
a) 我的实际错误:
源电子表格在第 516 行包含格式错误的数字,导致 excel #VALUE!
错误进入我生成的 SQL 应该是 DECIMAL 值的地方。 MySQL 在第 9 行指出错误并没有真正帮助我在第 5000 行附近找到问题。
b) 在线验证者: 为什么即使语句中没有错误值,在线验证器也会出现完全相同的错误仍然是个谜。事实上,他们现在仍然在完全相同的 SQL 上抛出错误,而在服务器上 运行 正确。