Rumah > Soal Jawab > teks badan
目标:A张表内有个 TIMESTAMP 字段,需要读取后插入到B表中;
问题:使用 cx_Oracle模块读取该字段时显示为 datetime.datetime(2016, 9, 1, 0, 0, 1, 288000) 样式;
使用 executemany 方法插入B表后,再次读取B表的该字段,显示为 datetime.datetime(2016, 9, 1, 0, 0, 1)
后面的毫秒单位消失了;
求解如何再插入后,保留后面的毫秒单位;
但是用 execute 方式插入,则格式正常,求解,非常感谢!
大致代码
sql_a = ''' SELECT HOSTURL,GETTIME,CPUUSERAGE,CPUSYSUSAGE,CPUIOUSAGE,CPUFREERATE,CREATE_DT,FLAG FROM PC_MONITOR_CPU_TX ''' ck_oracle.execute(sql_a) data = ck_oracle.fetchall() sql = "insert into PC_MONITOR_CPU_MX(HOSTURL,GETTIME,CPUUSERAGE,CPUSYSUSAGE,CPUIOUSAGE,CPUFREERATE,CREATE_DT,FLAG) values ( :HOSTURL,:GETTIME,:CPUUSERAGE,:CPUSYSUSAGE,:CPUIOUSAGE,:CPUFREERATE,:CREATE_DT,:FLAG)" ck_oracle.executemany(sql,data) ck_oracle.execute(sql_a) data = ck_oracle.fetchall() print(data)
三叔2016-11-09 13:25:44
在 stackoverflow上找到方法;
基本上是这样就可以了;
db_types = (d[1] for d in db1_cursor.description)
db2_cursor.setinputsizes(*db_types)