我有以下内容:(使用 ipython)
In [30]: con = cx_Oracle.connect('refill_test02/******@MYDB')
In [31]: cur = con.cursor()
In [32]: cur.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'")
In [33]: cur.execute("select to_date(:0), to_timestamp(:1) from dual", ['2013-03-12', '2013-03-12 08:22:31.332144'])
Out[33]: <__builtin__.OracleCursor on <cx_Oracle.Connection to refill_test02@MYDB>>
In [34]: cur.fetchall()
Out[34]:
[(datetime.datetime(2013, 3, 12, 0, 0),
datetime.datetime(2013, 3, 12, 8, 22, 31, 332144))]
In [35]: cur.execute("select to_date(:0), to_timestamp(:1) from dual", [u'2013-03-12', '2013-03-12 08:22:31.332144'])
Out[35]: <__builtin__.OracleCursor on <cx_Oracle.Connection to refill_test02@MYDB>>
In [36]: cur.fetchall()
Out[36]:
[(datetime.datetime(2013, 3, 12, 0, 0),
datetime.datetime(2013, 3, 12, 8, 22, 31, 332144))]
In [37]: cur.execute("select to_date(:0), to_timestamp(:1) from dual", [u'2013-03-12', u'2013-03-12 08:22:31.332144'])
---------------------------------------------------------------------------
DatabaseError Traceback (most recent call last)
/home/xxxxx/<ipython-input-37-8af80e5fc40c> in <module>()
----> 1 cur.execute("select to_date(:0), to_timestamp(:1) from dual", [u'2013-03-12', u'2013-03-12 08:22:31.332144'])
DatabaseError: ORA-01843: not a valid month
In [38]: cur.execute("select to_date(:0), to_timestamp(:1) from dual", [u'2013-03-12', '2013-03-12 08:22:31.332144'])
---------------------------------------------------------------------------
DatabaseError Traceback (most recent call last)
/home/xxxx/<ipython-input-38-bc628f006aa3> in <module>()
----> 1 cur.execute("select to_date(:0), to_timestamp(:1) from dual", [u'2013-03-12', '2013-03-12 08:22:31.332144'])
DatabaseError: ORA-01843: not a valid month
In [39]: cur.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'")
In [40]: cur.execute("select to_date(:0), to_timestamp(:1) from dual", [u'2013-03-12', '2013-03-12 08:22:31.332144'])
Out[40]: <__builtin__.OracleCursor on <cx_Oracle.Connection to refill_test02@MYDB>>
In [41]: cur.fetchall()
Out[41]:
[(datetime.datetime(2013, 3, 12, 0, 0),
datetime.datetime(2013, 3, 12, 8, 22, 31, 332144))]
出于某种原因,我不能将 unicode 字符串用于时间戳参数(IN[37]),更奇怪的是,在我这样做之后,我需要重置会话 NLS 格式,然后才能再次使用普通字符串。
我正在使用:Cx_Oracle 5.1.2 python 2.7.3 Oracle 10.2.0.1.0
有任何想法吗?
感谢您花时间阅读本文。