python==2.7
cx-Oracle==5.1.2
SQLAlchemy==1.1.5
pandas==0.19.2
我正在尝试使用以下代码将pandas数据帧插入到oracle(10g版本)表中:
import cx_Oracle
from sqlalchemy import Column, String, create_engine
oraengine = create_engine('oracle+cx_oracle://user:passwd@192.168.116.36:1521/LFdatabase', echo=True)
dbTable = 'zgb.asharetradealpha'
tmpDict = {'s_info_windcode':"000001.SZ", 'trade_dt':"20170929", 'alpha_001':0.01}
testDf = pd.DataFrame(data = tmpDict,index=[0])
pd.io.sql.to_sql(testDf, dbTable, oraengine.connect(), if_exists='append',index=False,)
已执行sql insert命令,但尚未将数据插入oracle表。调试I / O显示:
2017-10-27 15:14:34,163 INFO sqlalchemy.engine.base.Engine SELECT USER FROM DUAL
2017-10-27 15:14:34,164 INFO sqlalchemy.engine.base.Engine {}
2017-10-27 15:14:34,167 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60 CHAR)) AS anon_1 FROM DUAL
2017-10-27 15:14:34,167 INFO sqlalchemy.engine.base.Engine {}
2017-10-27 15:14:34,168 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS NVARCHAR2(60)) AS anon_1 FROM DUAL
2017-10-27 15:14:34,173 INFO sqlalchemy.engine.base.Engine {}
2017-10-27 15:14:34,187 INFO sqlalchemy.engine.base.Engine SELECT table_name FROM all_tables WHERE table_name = :name AND owner = :schema_name
2017-10-27 15:14:34,187 INFO sqlalchemy.engine.base.Engine {'name': u'zgb.asharetradealpha', 'schema_name': u'WINDFILESYNC'}
2017-10-27 15:14:34,194 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2017-10-27 15:14:34,196 INFO sqlalchemy.engine.base.Engine INSERT INTO "zgb.asharetradealpha" (alpha_001, s_info_windcode, trade_dt) VALUES (:alpha_001, :s_info_windcode, :trade_dt)
2017-10-27 15:14:34,196 INFO sqlalchemy.engine.base.Engine {'trade_dt': '20170929', 's_info_windcode': '000001.SZ', 'alpha_001': 0.01}
2017-10-27 15:14:34,213 INFO sqlalchemy.engine.base.Engine COMMIT