Points to note when python splicing oracle's sql insert table field is date type

params["insert_time"] = time.strftime("%Y-%m-%d %H:%M:%S")
k = ",".join([k for k in params.keys()])
v = tuple(v for v in params.values())
insert_sql = "insert into work_order (%s) values %s" % (k,v)
try:
    db.exec("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'")
    db.exec(insert_sql)
    db.commit()
    res = {"success": True, "message": "新增成功"}

Oracle wants to insert the time formatted by time.strftime(), you need to first set the nls_date_ format in the session to convert the date from python to oracle SET NLS_DATE_FORMAT

Guess you like

Origin blog.csdn.net/lystest/article/details/131067667