我使用 python 中的 Excel 工作表生成查询,然后使用 conn.execute(query)
执行查询。
但是,一个查询失败,因为它在某个值字符串的末尾有 \
。在下面的查询中查找 VALUES ("test", "ABCD\"
:
INSERT INTO S_account(Sub, AccName, AccTeam, Terr, AccOwner,
Level1, GAccount, Customer, City, State, EndCusName, AccID)
VALUES ("test", "ABCD\", "test", "test", "test", "No", "Yes",
"test", "test", "test", "asdasdas")
ON DUPLICATE KEY UPDATE
Sub = VALUES(Sub), AccName = VALUES(AccName), AccTeam = VALUES(AccTeam),
Terr = VALUES(Terr), AccOwner = VALUES(AccOwner), Level1 = VALUES(Level1),
GAccount = VALUES(GAccount), Customer = VALUES(Customer),
City = VALUES(City), State = VALUES(State), EndCusName = VALUES(EndCusName)
我尝试了以下命令,但没有帮助。
query = re.sub('\$', '' query)
最佳答案
您在 INSERT
语句中指定了 12 列,但仅包含 11 列的值:
INSERT INTO S_account(Sub, AccName, AccTeam, Terr, AccOwner, Level1,
GAccount, Customer, City, State, EndCusName, AccID)
VALUES ("test", "ABCD\", "test", "test", "test", "No",
"Yes", "test", "test", "test", "asdasdas", MISSING) -- no value for AccID
我认为反斜杠与它没有任何关系。您的错误消息实际上是否提到反斜杠是一个问题?
关于python - 由于字符串值之一的 "\",mysql 查询失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38648696/