python拼接oracle的sql插入表字段为date类型时注意事项

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想要插入time.strftime()格式化的时间,需要首先在会话中设置nls_date_格式,将日期从python转换为oracleSET NLS_DATE_FORMAT

你可能感兴趣的:(oracle,sql,数据库)