python 时间插入oracle date类型中

2021-05-18  本文已影响0人  逍遥_yjz

必须在会话中设置nls_date_格式,将日期从python转换为oracle

now_str = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

TM = datetime.datetime.strptime(now_str, '%Y-%m-%d %H:%M:%S')
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'")
sql = "INSERT INTO hoon(TM,CENTER_GAS24) VALUES ('%s','%s')" % (TM,CENTER_GAS24)

cursor.execute(sql)

在插入oracle之前,请执行以下操作

cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'")
上一篇 下一篇

猜你喜欢

热点阅读