import cx_Oracle
orcl = cx_Oracle.connect('username/password@db')
curs = orcl.cursor()
schema='my_schema'
curs.execute("""
select table_name from all_tables where owner=:own
order by 1
""",own=schema)
table_names=curs.fetchall()
tables=[]
class TableInfo:
def __init__ (self,tname):
self.name=tname
indexes={}
partitions={}
for tn in table_names:
t=TableInfo(tn[0])
indexlist={}
curs.execute("""
select index_name from all_indexes where table_name=:tbl
""",tbl=t.name)
index_names=curs.fetchall()
colnames=[]
for xn in index_names:
curs.execute("""
select column_name from all_ind_columns where index_name=:ind
""",ind=xn[0])
col_names=curs.fetchall()
for cn in col_names:
colnames.append(cn[0])
indexlist[xn[0]]=cn[0]
t.indexes=indexlist
tables.append(t)
for t in tables:
print t.name,t.indexes
curs.close()
orcl.close()
Friday, October 16, 2009
python script to list oracle tables and indexes
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment