Skip to content
Advertisement

How do I display attributes of table in oracle using python?

I connected Python to Oracle.

I am trying to display the attributes of the table using python i.e I want to display table schema. I am using ‘describe’ statement but while executing it gives me an error ' Invalid SQL Statement'.

I have done the following:

queryString = 'Describe Customer'
onCursor.execute(queryString)

“Customer” is the table name

Advertisement

Answer

In below sql you replace the table and owner name. It gives the columns names and datatype of column.

SELECT COLUMN_NAME, DATA_TYPE FROM ALL_TAB_COLUMNS WHERE TABLE_NAME='table_name' and OWNER='schema name'
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement