Я пытаюсь создать текст запроса оракула и затем передать этот запрос в программу-функцию cursor.execute.Это не работает, как ожидалось.Я могу напечатать правильный текст запроса, но не могу выполнить его в cursor.execute
.
# import modules
import cx_Oracle
# database connection
user=input('Enter the user for database : ')
passwd=input('enter the password for the above user : ')
conn_str=user+'/'+passwd+'@localhost/orcl'
conn=cx_Oracle.connect(conn_str)
# creation of cursor
cursor=conn.cursor()
cur=cursor.execute('select distinct emp_name from employee')
employee=[]
for i in cur:
print(i[0])
employee.append(i[0])
print(employee)
cur=cursor.execute('select distinct month_name from employee')
months=[]
for i in cur:
print(i[0])
months.append(i[0])
print(months)
for i in employee:
for j in months:
query=str('select salary from employee where emp_name=\''+i[0]+'\' and month_name = \''+j[0:3]+'\'')
print(query)
cur=cursor.execute(query)
print(cur)
#closing cursor and connection
cursor.close()
conn.close()