文件操作-oracle数据库

import cx_Oracleimport os
from openpyxl import load_workbook

os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'



def updateOracle(sql):
    os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'  # 读取数据中文全是问号的问题
    conn = cx_Oracle.connect('loan_c/loan_c@127.0.0.1:1521/testdb')
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()
    cursor.close()
    conn.close()


def selectOracle(sql):
    os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'  # 读取数据中文全是问号的问题
    conn = cx_Oracle.connect('loan_c/loan_c@127.0.0.1:1521/testdb')
    cursor = conn.cursor()
    cursor.execute(sql)
    s = cursor.fetchone()[0]
    cursor.close()
    conn.close()
    return s




#----------------------------------------------------执行-------------------------------------------
wb = load_workbook("renhanggaoduan.xlsx")
ws = wb.active



#更新datetime.date格式到oralce数据库

updateOracle("update lb_t_customter_info set birthday=to_date('%s','yyyy-mm-dd') where id =(select r.fk_cust_id from lb_t_into_customer_ref r where r.fk_into_app_id = '120154630763')"%((ws["D242"].value).date()))

 

posted @ 2019-07-22 10:34  不不田鼠  阅读(219)  评论(0编辑  收藏  举报