MySQL查询失败,原因是字符串值末尾包含“\”。

2024-09-30 06:21:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用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)

Tags: testcitycustomerquerystatevaluesabcdterr
1条回答
网友
1楼 · 发布于 2024-09-30 06:21:56

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

我认为反斜杠与此无关。您的错误消息是否确实提到反斜杠是一个问题

相关问题 更多 >

    热门问题