【问题标题】:Missing headers reading Oracle data in Python缺少在 Python 中读取 Oracle 数据的标头
【发布时间】:2022-02-18 05:41:02
【问题描述】:

我想从 Python 连接到 Oracle 数据库数据。我用代码做到了:

import cx_Oracle

CONN_INFO = {
    'host': 'xxx.xx.xxx.x',
    'port': 12345,
    'user': 'user_name',
    'psw': 'my_password',
    'service': 'abc.xyz.com',
}

CONN_STR = '{user}/{psw}@{host}:{port}/{service}'.format(**CONN_INFO)

connection = cx_Oracle.connect(CONN_STR)

c = connection.cursor()
rs = c.execute('select * from my_table')

df = pd.DataFrame(rs)

但是,我注意到所有标题都丢失了,取而代之的是 0, 1, 2, 3, ... This answer 建议更改 pagesize 但这会更改 Oracle 设置吗?我想避免在 Oracle DB 中进行任何更改。有没有办法解决这个问题?

【问题讨论】:

    标签: python pandas oracle


    【解决方案1】:

    使用pd.read_sql 似乎可行:

    query = """select * from my_table"""
    df_ora = pd.read_sql(query, con=connection)
    

    【讨论】:

      猜你喜欢
      • 2021-02-03
      • 2021-01-06
      • 2013-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 2020-05-30
      相关资源
      最近更新 更多