本帖最后由 wushaominkk 于 2019-12-19 08:48 编辑
通过Python脚本进行两个库数据的迁移
刚接触PY,希望大家多指教
[Python] 纯文本查看 复制代码 from db_conf.dbtemplate import OracleTemplate
from db_conf.dbtemplate import MysqlTemplate
from entity.NormalTable import Prod_Inst
def batch_prod_qsub():
orcal_conn = OracleTemplate('NEWCRM_ASSET')
mysql_conn = MysqlTemplate('cusdb')
sql_prod ="select * from data_adm.cgtmp_prod_inst_attr2019121303"
orcal_conn.execute(sql_prod)
ora_result1 = orcal_conn.fetchall(True)
#print(ora_result1)
ora_c1 = len(ora_result1)
for or1 in range(ora_c1):
ora_result2 =ora_result1[or1]
#print(ora_result2)
sql_header = " INSERT INTO prod_inst_attr( "
sql_fields = ""
sql_tail = " ) VALUES( "
val_fields = ""
val_list = []
# print(c1)
for c1 in ora_result2:
if sql_fields == "":
sql_fields = c1
sql_val = " %s "
val_list.append(ora_result2[c1])
else:
sql_fields += " , " + str(c1)
sql_val += " , %s "
val_list.append(ora_result2[c1])
sql_text = sql_header + sql_fields + sql_tail + sql_val + " ) "
#print(val_list)
mysql_conn.execute(sql_text,val_list)
orcal_conn.commit()
orcal_conn.close()
mysql_conn.commit()
mysql_conn.close()
batch_prod_qsub() |