类型错误:在字符串格式化期间,并非所有参数都已转换

时间:2019-05-27 10:00:38

标签: python python-2.7

Python函数从本地数据库获取数据。运行此代码时出现错误

TypeError: not all arguments converted during string formatting

我不知道这有什么问题。

如果我将on_date = "'" + on_demand_date + "'"替换为on _date = 'sysdate - 1',则此功能不会产生错误。

 def get_history_of_code_list_for_AOP(db_cur, aop_vendor_list, code_list, 
 on_demand_date = ""):
 """ Fetches all updated/created offices under AOP vendors in on_demand_date for given set of IND"""

if on_demand_date:
    on_date = "'" + on_demand_date + "'"
else:
    on_date = 'sysdate - 1'

print "{0} : Getting code list History of AOP for " + on_date + " based on aop_vendor_list and code_list"\
              .format(Util.get_current_time())

in_ven_clause = ', '.join([':id%s' % x for x in xrange(len(code_list), len(code_list)+len(aop_vendor_list))])
in_ind_clause = ', '.join([':id%s' % x for x in xrange(len(code_list))])

code_list.extend(aop_vendor_list)

hist_query = "SELECT H.amid,H.date_time,H.action_code,H.HISTORY_CODE ,H.new_value,H.old_value,"\
            " O.vendor_name,O.ns_id,O.OFFICE_NAME FROM "\
            "(select amid,action_code,history_code,date_time,new_value,old_value,row_number() over "\
            "(partition by amid,history_code order by amid,date_time desc) as rn "\
            "from rfd_data_history where "\
            "trunc(date_time) = trunc(to_date(" + on_date + ",'DD-MON-RR HH24:MI:SS')) "\
            "and history_code IN (%s) order by amid) H "\
            "inner join rfd_sec_office O ON "\
            "H.amid = O.amid "\
            "and O.Vendor_name in (%s) "\
            "and H.rn = 1" % (in_ind_clause,in_ven_clause)

print "{0} : Query To be executed is:{1}".format(Util.get_current_time(), hist_query)
db_cur.execute(hist_query,code_list)
return db_cur.fetchall()

如何使此代码正常工作。执行查询时失败

0 个答案:

没有答案