import re
import traceback
import cx_Oracle
from loglib import log
import os
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'
try:
ora_tns = cx_Oracle.makedsn("IP地址","1521","tzqdev") # 创建tns
infocenter_oracle_client = cx_Oracle.connect("账号","密码",ora_tns) # 创建oracle client
log.info("cx_Oracle连接成功!!")
cursor = infocenter_oracle_client.cursor() #创建游标
except Exception as e:
traceback.print_exc()
log.error("cx_Oracle连接失败:")
def write_context(dict1):
zd = ",".join(dict1.keys()) #Key 作为字段
val = ",".join([f"'{x}'" for x in dict1.values()]) #values 作为内容
try:
insert_sql = f"insert into infocenter.ESG({zd}) values ({val})"
cursor.execute(insert_sql)
infocenter_oracle_client.commit()
except Exception as e:
traceback.print_exc()
传入一个dict格式的对象进去
write_context(dict1)
网友评论