【问题标题】:Unable to execute "DESCRIBE ARADMIN.EPM_TechnicianInformation" in python jupyter notebook with cxOracle无法使用 cxOracle 在 python jupyter notebook 中执行“DESCRIBE ARADMIN.EPM_TechnicianInformation”
【发布时间】:2021-11-08 14:45:44
【问题描述】:

当我执行如下查询“DESCRIBE ARADMIN.EPM_TechnicianInformation”时:

connection = cx_Oracle.connect(user=username, password=userpwd, dsn=dsn, encoding="UTF-8")
cursor = connection.cursor()
results = cursor.execute(" DESCRIBE ARADMIN.EPM_TechnicianInformation")

它正在给予

DatabaseError: ORA-00900: invalid SQL statement

如何使用 cx_Oracle 创建查询“DESCRIBE ARADMIN.EPM_TechnicianInformation”? 我想获取表格的列详细信息。

请帮忙!谢谢!

【问题讨论】:

  • 你尝试添加';'在语句的末尾?
  • @Carlo 是的,还是不行

标签: python sql jupyter-notebook cx-oracle ora-00900


【解决方案1】:

'desc' 命令是 SQL*Plus 命令,不是数据库或 cx_Oracle 理解的。

请查看关于 cx_Oracle 的光标description 属性的文档。

您可以尝试以下方法:

# sql for column details
sql = "SELECT * from ARADMIN.EPM_TechnicianInformation"
cursor.execute(sql)
print(cursor.description)
# This will print out the column description as a list, with each item referring to each column.

【讨论】:

    【解决方案2】:

    How to execute a SQL script with cx_oracle 读取,cx_Oracle 似乎不理解 SQL Plus 特定语句

    您可以尝试通过以下方式获取所需的信息:

    SELECT * FROM ALL_TABLES WHERE OWNER= 'ARADMIN' AND TABLE_NAME = 'EPM_TechnicianInformation'
    

    这也会给你桌子上的信息

    【讨论】:

    • 我在使用这个时收到以下错误 - DatabaseError Traceback (最近一次调用最后一次) in ----> 1 results = cursor.execute ("SELECT * FROM ALL_TABLES WHERE SCHEMA = 'ARADMIN' AND TABLE_NAME = 'EPM_TechnicianInformation'").fetchall() DatabaseError: ORA-00904: "SCHEMA": invalid identifier
    • @Bharti 已编辑,它是 OWNER 而不是 SCHEMA,抱歉出现错误
    • @Bharti 在查询这些对象(ALL_TABLES、ALL_VIEWS 等)时查找 oracle 文档,您会很容易找到信息,它们非常有用
    猜你喜欢
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 2020-05-18
    • 2020-03-26
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多