python插入Oracle数据库日期类型字段相关问题

1.Oracle字段设置为DATE类型

2.连接Oracle数据库

import cx_Oracle,os,datetime

os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'

db = cx_Oracle.connect('N2ADMIN/N2ADMIN@ip:1521/orcl')

cursor = db.cursor()

3.python的字符串类型

sql="insert into table(column) values(to_date('%s','yyyy-MM-dd hh24:mi:ss'))"%('2005-01-01 13:14:20')

cur.execute(sql)

db.commit()

4.python的datetime类型

sql="insert into table(column) values(to_date('%s','yyyy-MM-dd hh24:mi:ss')))"%(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

cur.execute(sql)

db.commit()

原文地址:https://www.cnblogs.com/pythonsnowhiwte/p/13524980.html