Dec-28-2017, 03:39 PM
Hi All,
I am new to python coding .
I am using oracle 11g db in my environment .
I want to connect different users in database and fetch the data from tables.
i trying to create dynamic database connections but i am not able to complete.
Below is my code,please can you correct and help me on dynamic database connection.
import cx_Oracle
shuttles = ['columbia','Brazil']
for c in shuttles:
SQL_columbia='select * from departments order by department_id'
SQL_Brazil='select * from departments order by department_id'
SQL='SQL'+'_'+c
con_columbia=("chr","hr","localhost/xe")
con_Brazil=("bhr","hr","localhost/xe")
dbdetails='con'+'_'+c
mydb=dbdetails
print mydb
con=cx_Oracle.connect(mydb)
print con
cur = con.cursor()
cur.execute(SQL)
for result in cur:
print result
cur.close()
con.close()
I am new to python coding .
I am using oracle 11g db in my environment .
I want to connect different users in database and fetch the data from tables.
i trying to create dynamic database connections but i am not able to complete.
Below is my code,please can you correct and help me on dynamic database connection.
import cx_Oracle
shuttles = ['columbia','Brazil']
for c in shuttles:
SQL_columbia='select * from departments order by department_id'
SQL_Brazil='select * from departments order by department_id'
SQL='SQL'+'_'+c
con_columbia=("chr","hr","localhost/xe")
con_Brazil=("bhr","hr","localhost/xe")
dbdetails='con'+'_'+c
mydb=dbdetails
print mydb
con=cx_Oracle.connect(mydb)
print con
cur = con.cursor()
cur.execute(SQL)
for result in cur:
print result
cur.close()
con.close()