我有以下幾點:(使用IPython中)cx_Oracle「ORA-01843:不是有效的一個月使用Unicode參數
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 [email protected]>>
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 [email protected]>>
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 [email protected]>>
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 蟒蛇2.7.3 甲骨文10.2.0.1.0
任何想法?
謝謝您的閱讀時間。
它使用的格式字符串工作正常,問題是,SQL代碼Django在保存模型時產生的,我想避免手動做插入。感謝你的回答。 – Magarato 2013-04-30 21:00:40