【发布时间】:2017-10-03 11:06:06
【问题描述】:
import cx_Oracle
from datetime import datetime
#reading query from file
f = open('C:/Users/pubhatia/Documents/learning/python/query/test.sql')
#print(f.read())
filer = f.read()
print(filer)
print(repr(filer))
f.close()
#filer3=filer
filer=filer.replace("\'","")
#print( repr(filer3 )
filer2="select * from dual"
if filer==filer2:
print('same value')
else:
print ('no same ')
#create connection string
conn_str = u'user/pwd@db'
#setting up connection
conn = cx_Oracle.connect(conn_str)
c = conn.cursor()
#c.execute("select WORK_PHONE,source_sys_cd,source_sys_id from mdm_people_standard where source_sys_cd ='%s' AND WORK_PHONE IS NOT NULL"%(source_name))
c.execute(filer2)
start_time = datetime.now()
for row in c:
print( row)
conn.close()
end_time = datetime.now()
print('Duration: {}'.format(end_time - start_time))
我无法运行存储在文本文件中的 sql 查询,因为它给了我一个错误: 回溯(最近一次通话最后): 文件“oracle_test.py”,第 18 行,在 c.execute(文件管理器) cx_Oracle.DatabaseError: ORA-00933: SQL 命令未正确结束
So just to check what is stored in filer I found
filer value is ' "select * from dual" '
and that is why I am unable to run query
Now I am unable to remove it as this string.
Please help
test.sql is storing simple select statement
"select * from dual"
【问题讨论】:
标签: python-3.x