python - Python3 ODBC 执行许多
问题描述
我正在尝试使用 python odbc 库将数据从 1 个 oracle 表复制到另一个模式中。这就是我正在做的
source = SomeString (source Oracle DataTable)
target = SomeString (target Oracle DataTable)
连接到数据源以检索数据:
source_data = pyodbc.connect(source)
source_cursor = source_data.cursor()
连接到目标数据源
target = pyodbc(target)
target_cursor = target.cursor()
我现在声明我的源数据查询
source_query = SELECT * FROM TABLE where TYPE = X
我将数据放入数据框中,然后将其转换为列表
data = pd.read_sql(source_query, source)
data = data.values.tolist()
我现在正试图将我的“数据”列表中的数据插入到我的目标表中。我声明了一个插入语句,然后按如下方式运行 executemany:
sql = "INSERT INTO SCHEMA.TABLE (column1, column 2, etc...) Values (?,?, etc..)
现在,由于我建立了数据和目标连接,因此我执行以下操作
target_cursor.executemany(sql, data)
我在下面收到以下错误,奇怪的是代码在新表中正确插入了 1 行,然后它失败了,没有任何反应。
你能指导我如何解决这个问题吗?
我收到以下错误:
C:\WinPy3770x64\python-3.7.7.amd64\lib\encodings\utf_16_le.py in decode(input, errors)
15 def decode(input, errors='strict'):
---> 16 return codecs.utf_16_le_decode(input, errors, True)
17
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 184-185: illegal encoding
The above exception was the direct cause of the following exception:
SystemError Traceback (most recent call last)
<ipython-input-70-ec2d225d6132> in <module>
----> 1 target_cursor.executemany(sql_statement, data)
SystemError: <class 'pyodbc.Error'> returned a result with an error set
解决方案
推荐阅读
- python - 如何使用 kubernetes 和 skaffold 调试 python 代码?
- kotlin - kotlin 文档中的“Common”、“JVM”、“JS”和“JVM”标签表示什么?
- c# - 如何在c#中检查计时器的经过时间
- php - 在 React 中由 Axios 调用时 API 中的 PHP-Session 发生变化
- php - 删除某些字段后,标签和值未在 my-account/edit-address/ 中正确显示
- .net - EventLog.SourceExists 在 Windows Server 2019 上失败
- javascript - javascript乘法表顺序
- elixir - 默认 ExUnit.Case 使用 `async: true`
- python - 在 Windows 中为项目设置相对 pythonpath (Visual Studio Code)
- jmeter - 如果 Taurus GUI 与变量一起使用,它不会反映解析参数