【问题标题】:cx_Oracle returning zero rowscx_Oracle 返回零行
【发布时间】:2019-10-26 23:06:22
【问题描述】:

我是通过 python 3.6 连接到 oracle db(版本 19.3)的新手。我没有得到任何行作为回报。请告诉我我在这里缺少什么?

我认为所有连接都设置正确,因为它没有显示任何连接错误或无效密码错误。尝试使用 fetchall()、fetchmany()、rowcount 等。一切都返回零。我尝试打印光标对象本身,它正在工作。我在我的数据库中运行了查询。我在本地安装了 Oracle DB 19.3,使用 Oracle SQL developer 运行 SQL。我还需要安装什么吗?

import cx_Oracle
conn = cx_Oracle.connect("username", "password", "localhost/orcl")
cur = conn.cursor()
cur.execute('select * from emp')
for line in cur:
    print(line)
cur.close()
conn.close()

【问题讨论】:

  • 这在系统重启后开始工作,任何正在阅读这篇文章的人请重新启动一次,然后再挠头。

标签: python-3.x cx-oracle


【解决方案1】:

运行后

delete from emp;

您的 python 程序将在您报告时显示零行。

您可能希望在运行之前插入一行或多行。

您可能还会发现sqlalchemy 提供的界面更方便。 它提供跨 Oracle 和其他数据库后端的应用程序可移植性。 参见https://developer.oracle.com/dsl/prez-python-queries.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多