首页 > 解决方案 > 从 oracle 数据库服务器中提取表名

问题描述

我可以访问一个连接到商店的 oracle11g 服务器,并且有一个软件可以在 softare 中获取报告,但该软件是封闭源代码的。因为我在数据库中有一个用户名,我可以从软件访问所有报告,但我想自动化一些工作并想编写一个 python3 脚本来做到这一点。我只需要知道 DB 中的表名。我想要一个在 oracle 中返回表名的代码。我可以从“PLSQL Developer”和我未完成的 python 代码访问数据库。

import cx_Oracle
con = cx_Oracle.connect('username/password@serveraddress/dbname')
print (con.version)
cur =con.cursor()
cur.execute(" SOME ORACLE CODE")
#cur.execute('select * from tablesname orderby id' )

for i in cur:
    print (i)
con.close()

那么什么是可以执行并将表名返回给我的代码?

ps:我什至用wireshark找出程序发送到服务器的代码是什么,但数据包中没有表名。:(

ps 2:欢迎任何有创意和不寻常的答案。

标签: oracledictionarycatalog

解决方案


您可以使用

select table_name
  from user_tables
 order by table_name

或者

select table_name
  from cat
 where table_type = 'TABLE'  
 order by table_name

派生当前用户中所有表的名称。wherecatuser_catalog数据字典视图的同义词,user_tables是数据库在安装过程中自动创建的另一个数据字典视图。


推荐阅读