Re: [cx-oracle-users] cx_Oracle4.3.1: - describe table query is not working!!!
Brought to you by:
atuining
From: Richard M. <ri...@we...> - 2007-05-09 09:07:57
|
Piyush Chechani wrote: > Hi all... > > Just have a look on the code below... > > (We have 'sample database with one of the table 'tab1' & user 'demo') > > #We are trying to fetch all the columns from the table specified & their > type. > #This is done by using 'describe <table-name>' sql query in Oracle. > > import cx_Oracle > > connection = cx_Oracle.Connection("demo/demo@sample") > cursor = connection.cursor() > cursor.execute("describe tab1") > for row in cursor.description: > print "Column Name is: ",row[0] > print "Column Type is: ", row[1] > print "------------------------------------------------" > > #But this is giving error that is: - cx_Oracle.DatabaseError: ORA-00900: > invalid SQL statement > #I got some other method to implement this, but that is a bit lengthy. > (can put that also if required) > #My quetion is that does cx_Oracle supports 'describe <table-name>' query > or not??? I don't think it does (it's not really a query). You can get the same information using a query of the data dictionary. For example select table_name from user_tables; -- Get a list of tables select column_name, data_type from all_tab_columns where table_name = 'RESELLER'; -- Get the names and types of the table RESELLER. Cheers Rich. -- Richard Moore, Principal Software Engineer, Westpoint Ltd, Albion Wharf, 19 Albion Street, Manchester, M1 5LN, England Tel: +44 161 237 1028 Fax: +44 161 237 1031 |