使用python在oracle中将日期作为整数插入

时间:2016-12-27 07:12:26

标签: python oracle datetime

我想使用python将日期作为整数插入oracle。以下是我的代码。

import cx_Oracle
import pandas as pd
import datetime
import numpy
import math
import time

def update_output_table_last_transaction(customer_id_list,column_name,column_value_list) :
num_rows_to_add = len(customer_id_list)
conn = cx_Oracle.connect(conn_str)
c = conn.cursor()

for i in range(0,num_rows_to_add,1) :
    print type(column_value_list[i]) 
    print column_value_list[i]
    c.execute("""UPDATE output SET """+column_name+""" = %s WHERE customer_id = %s""" %(column_value_list[i].datetime.datetime.strftime('%y%m%d'),customer_id_list[i]))
    conn.commit()
print "Completed updating " + column_name

last_transaction_date_df = pd.read_sql("""select distinct b.customer_id, MAX(a.date_of_issue) as "LAST_TRANSACTION_DATE" from 
transaction_fact a inner join customer_dim b on a.customer_id = b.customer_id group by b.customer_id""",conn)

 update_output_table_last_transaction(list(last_transaction_date_df['CUSTOMER_ID']),'LAST_TRANSACTION_DATE',list(last_transaction_date_df['LAST_TRANSACTION_DATE']))

我跑了上面的代码,但它给了我以下错误: AttributeError:'Timestamp'对象在行上没有属性'datetime',其中使用'strftime'方法将日期(作为整数)插入数据库。

如果这是一个愚蠢的怀疑,请忽略,我是新手。

0 个答案:

没有答案