0

When I execute query "DESCRIBE ARADMIN.EPM_TechnicianInformation" like below:

connection = cx_Oracle.connect(user=username, password=userpwd, dsn=dsn, encoding="UTF-8")
cursor = connection.cursor()
results = cursor.execute(" DESCRIBE ARADMIN.EPM_TechnicianInformation")

It is giving

DatabaseError: ORA-00900: invalid SQL statement

How can I create query "DESCRIBE ARADMIN.EPM_TechnicianInformation" with cx_Oracle? I want to get column details of the table.

Please help! Thanks!

Carlo Prato
  • 326
  • 4
  • 21
Bharti
  • 15
  • 4

2 Answers2

1

The 'desc' command is a SQL*Plus command, not something the database or cx_Oracle understands.

Please check the documentation on cursor description property of cx_Oracle.

You can try the following:

# sql for column details
sql = "SELECT * from ARADMIN.EPM_TechnicianInformation"
cursor.execute(sql)
print(cursor.description)
# This will print out the column description as a list, with each item referring to each column.
Sharad
  • 66
  • 8
0

reading from How to execute a SQL script with cx_oracle it looks like SQL Plus specific statements are not understood by cx_Oracle

you can try getting the information you need by doing :

SELECT * FROM ALL_TABLES WHERE OWNER= 'ARADMIN' AND TABLE_NAME = 'EPM_TechnicianInformation'

This will give you infos on the table as well

Carlo Prato
  • 326
  • 4
  • 21
  • I am getting the below error when using this - DatabaseError Traceback (most recent call last) in ----> 1 results = cursor.execute("SELECT * FROM ALL_TABLES WHERE SCHEMA = 'ARADMIN' AND TABLE_NAME = 'EPM_TechnicianInformation'").fetchall() DatabaseError: ORA-00904: "SCHEMA": invalid identifier – Bharti Sep 13 '21 at 11:11
  • @Bharti EDITED, it's OWNER not SCHEMA, sorry for the error – Carlo Prato Sep 13 '21 at 12:02
  • @Bharti Look for oracle dcocumentation when querying these objects ( ALL_TABLES, ALL_VIEWS, etc) you will find informations easily and they are very useful – Carlo Prato Sep 13 '21 at 12:07