问题
I need to insert a timestamp with milliseconds in an Oracle table with Python 3.6 and cx_Oracle 6.4.1. The insert is done okay but I am losing the milliseconds on the way.
The timestamp is passed as a datetime object. Any ideas how I could keep the milliseconds without making a to_timestamp() in the SQL itself? I would like to keep passing a datetime in the SQL transaction. I use executemany() as the idea is to insert multiple records at once.
import cx_Oracle
import datetime
conf = {
'username': 'USERNAME',
'password': 'PASSWORD',
'tns': 'TNS'
}
d = datetime.datetime.now()
print(d)
db_conn = cx_Oracle.connect(conf['username'], conf['password'], conf['tns'], encoding='UTF-8', nencoding='UTF-8')
cursor = db_conn.cursor()
sql_insert = "INSERT INTO {} VALUES {}".format('timestamp_test', '(:1)')
cursor.prepare(sql_insert)
cursor.executemany(None, [[d]])
db_conn.commit()
来源:https://stackoverflow.com/questions/52145119/insert-timestamp-with-milliseconds-in-oracle-with-cx-oracle-and-python-3-6