1

how can i see a list of tables in an oracle database in python? Right now I am just having the connection:

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() 

which prints out the version: Database version: 12.2.0.1.0

But how can I see a list of all tables which are available in that database? Somethinglike: Salesdata, Buyingdata

How can I see a list of all the tables?

1
  • 1
    There is no 'python' way to do this - you need to use a query, as shown in your code and answer. The exact query will depend on whether you want to list tables you own, and/or the tables have access to. Or whether you mean all tables in the DB. Commented Jun 9, 2020 at 23:20

1 Answer 1

4

If you want only list of tables (without table owner):

cur.execute("SELECT table_name  FROM dba_tables")
for row in cur:
    print row
Sign up to request clarification or add additional context in comments.

3 Comments

Or use user_tables if you want to see 'your' tables, or 'all_tables' to see those that are accessible to you even if they are not in you schema.
this gives me a list of all table names back?
Yes that will give all table names in all database schemas provided that you have SELECT privilege on DBA_TABLES either directly or with a role like SELECT_CATALOG_ROLE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.