是什么造成的?第39行第85列出现词汇错误。遇到:“\r”(13),在:”“

2024-10-02 02:27:57 发布

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

你好,我想在SQL Server 2017中插入一个panda数据帧,我得到了这个

Lexical error at line 39, column 85.  Encountered: "\r" (13), after : ""

在这一点上

cursor.execute("INSERT INTO dbo.someTable([records], [id], [userid], [originid],
[targetid],[targetname], [start_date], [end_date],[next_offset], [set_id])                
values (?,?,?,?,?, ?,?,?,?,?)",  
row['records'], row['id'],row['userid'], row['usernanme'], 
row['originid'], row['targetid'], row['targetname'],
row['start_date'], row['end_date'], row['next_offset'], row['set_id'])

剩下的看起来还可以。。。据我所知这是对的?我做错什么了?Thnks公司


Tags: idsqldateserverstartoffsetnextend
2条回答

似乎有代码无法识别的换行符,这在unix和windows之间是不同的。”\r\n“代表windows/DOS,而“\n”代表unix,而“\r”代表mac。在windows/DOS上创建的内容传递到unix时将出现问题。你知道吗

重新格式化字符串,如下所示:

cursor.execute(
    """
    INSERT INTO dbo.someTable([records],
    [id], [userid], [originid], [targetid], [targetname],
    [start_date], [end_date], [next_offset], [set_id])
    values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    """,
    (row['records'], row['id'], row['userid'], row['usernanme'],
    row['originid'], row['targetid'], row['targetname'],
    row['start_date'], row['end_date'], row['next_offset'], row['set_id']))

而且,参数周围似乎缺少括号。你知道吗

相关问题 更多 >

    热门问题