必须在会话中设置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'")
网友评论