【问题标题】:Get a list of all tables in Oracle Database in Python用 Python 获取 Oracle 数据库中所有表的列表
【发布时间】:2020-06-09 13:32:20
【问题描述】:

如何在 python 中查看 oracle 数据库中的表列表?现在我只是连接:

import cx_Oracle
db_connection_string = 'username/passwort1@server:port/servername'
con = cx_Oracle.connect(db_connection_string)
print("Database version:", con.version)
cur.execute("SELECT owner, table_name  FROM dba_tables")
con.close() 

打印出版本:数据库版本:12.2.0.1.0

但是我怎样才能看到该数据库中所有可用表的列表呢? 就像是: Salesdata, Buyingdata

如何查看所有表格的列表?

【问题讨论】:

  • 没有“python”方法可以做到这一点 - 您需要使用查询,如您的代码和答案中所示。确切的查询将取决于您是否要列出您拥有的表,和/或这些表有权访问。或者您的意思是数据库中的所有表。

标签: python sql oracle


【解决方案1】:

如果您只想要表列表(没有表所有者):

cur.execute("SELECT table_name  FROM dba_tables")
for row in cur:
    print row

【讨论】:

  • 如果您想查看“您的”表,请使用 user_tables,或者使用“all_tables”查看您可以访问的那些,即使它们不在您的架构中。
  • 这给了我所有表名的列表?
  • 是的,这将提供所有数据库模式中的所有表名,前提是您直接或具有类似 SELECT_CATALOG_ROLE 的角色对 DBA_TABLES 具有 SELECT 权限。
猜你喜欢
  • 2010-12-21
  • 2010-09-17
  • 1970-01-01
  • 2023-03-24
  • 2013-01-27
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 2020-12-10
相关资源
最近更新 更多