导入sqlalcheme
import sqlalchemy
写连接串
oracle+cx_Oracle://user:pass@host:port/dbname[?key=value&key=value...]
to_sql写入数据
from sqlalchemy import create_engine
conn_string='oracle+cx_oracle://user:pass@host:port/dbname'
engine = create_engine(conn_string, echo=False)
df.to_sql('users', con=engine)
engine.execute("SELECT * FROM users").fetchall()
[(0, 'User 1'), (1, 'User 2'), (2, 'User 3')]
参考
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_sql.html
https://docs.sqlalchemy.org/en/latest/dialects/oracle.html