2

I want to list and describe the tables present in an Oracle database.

To do this by connecting to the database with a client such as SQL Plus, a working approach is:

  1. List the tables:

    select tablespace_name, table_name from all_tables;

  2. Get columns and data types for each table:

    describe [table_name];

However when using cx_Oracle through python, cur.execute('describe [table_name]') results in an 'invalid sql' error.

How can we use describe with cx_Oracle in python?

1
  • 1
    DESCRIBE is a SQLPlus "client side" command. SQLPlus doesn't send it to the database. It is not a SQL statement so the database doesn't understand it. Commented Feb 27, 2018 at 21:21

2 Answers 2

4

It seems you can't.

From cx_Oracle instead of describe use:

cur.execute('select column_name, data_type from all_tab_columns where table_name = [table_name]')

(From Richard Moore here http://cx-oracle-users.narkive.com/suaWH9nn/cx-oracle4-3-1-describe-table-query-is-not-working)

Sign up to request clarification or add additional context in comments.

Comments

2

As noted by others there is no ability to describe directly. I created a set of libraries and tools that let you do this, however. You can see them here: https://github.com/anthony-tuininga/cx_OracleTools.

Comments

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.