The following scripts connect to an Oracle database and execute queries.
import cx_Oracle
connection = cx_Oracle.connect("aisxxx","xxxxxxx",\
"orcl.ctbxxxxxxx.us-east-1.rds.amazonaws.com:1521/orcl")
# username, password, host:port number/service name
cur = connection.cursor()
# query table
cur.execute("select table_name, tablespace_name from user_tables order by 1")
for each in cur.description:
print(each[0:2])
for col_1, col_2 in cur.fetchall():
print(col_1+" "+col_2)
cur.close()
connection.close()
Outputs are the following.
('TABLE_NAME', )
('TABLESPACE_NAME', )
T_TEST USERS
No comments:
Post a Comment