【问题标题】:Reading Sql query stored in CSV file in python is not working在python中读取存储在CSV文件中的Sql查询不起作用
【发布时间】: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


    【解决方案1】:

    我存储 SQL 查询的文本文件中有错误。

    我以以下格式存储它 “从对偶中选择 *” 按下 Enter

    但需要按以下格式存储

    从对偶中选择 * 然后什么都不按

    【讨论】:

      猜你喜欢
      • 2018-07-26
      • 2014-11-17
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      • 2023-03-22
      • 2013-09-25
      • 2016-10-30
      相关资源
      最近更新 更多