奇怪的 Oracle 错误:“文本格式无效”
我正在尝试使用这段代码从 DATA_TYPE=NUMBER(1,0) 的列中获取一些数据:
import cx_Oracle
conn = cx_Oracle.connect(usr, pwd, url)
cursor = conn.cursor()
cursor.execute("SELECT DELETED FROM SERVICEORDER WHERE ORDERID='TEST'")
print(cursor.fetchone()[0])
它因此抱怨:
Traceback (most recent call last):
File "main.py", line 247, in <module>
check = completed()
File "main.py", line 57, in completed
deleted = cursor.fetchone()[0]
cx_Oracle.DatabaseError: OCI-22061: invalid format text [T
用 DATA_TYPE=VARCHAR2 的列替换“DELETED”列不会引发这样的抱怨。
I'm trying to fetch some data from a column whose DATA_TYPE=NUMBER(1,0) with this piece of code:
import cx_Oracle
conn = cx_Oracle.connect(usr, pwd, url)
cursor = conn.cursor()
cursor.execute("SELECT DELETED FROM SERVICEORDER WHERE ORDERID='TEST'")
print(cursor.fetchone()[0])
which complains thus:
Traceback (most recent call last):
File "main.py", line 247, in <module>
check = completed()
File "main.py", line 57, in completed
deleted = cursor.fetchone()[0]
cx_Oracle.DatabaseError: OCI-22061: invalid format text [T
Replacing 'DELETED' column with one whose DATA_TYPE=VARCHAR2 does not throw such a complaint.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我现在使用带有 Unicode 支持的 cx_Oracle 5.0.4 遇到这个问题。上述接受的解决方案对我不起作用。问题中的 DELETED 列是一个数字列,这就是导致此错误的原因。
根据邮件列表( http://comments.gmane.org /gmane.comp.python.db.cx-oracle/2390 )这可能是 Oracle 中的一个错误,仅在支持 Unicode 的 cx_Oracle 中显示。
从链接:
“当我在没有 Unicode 支持的情况下构建 cx_Oracle 时,一切都按预期工作。
当我构建带有 Unicode 支持的 cx_Oracle 时,尝试使用查询
返回一个数值(例如):
导致此异常:
“
我为解决这个问题所做的工作是在 select 语句上执行:
它非常丑陋,但它有效。
I am running in to this problem now using cx_Oracle 5.0.4 with Unicode support. The above accepted solution did not work for me. The DELETED column in the question is a Numeric column, which is what causes this bug.
According to the mailing list ( http://comments.gmane.org/gmane.comp.python.db.cx-oracle/2390 ) it may be a bug in Oracle that shows only in cx_Oracle with Unicode support.
from the link:
"When I build cx_Oracle without Unicode support, it all works as expected.
When I build cx_Oracle with Unicode support, attempting to use a query
that returns a numeric value (such as):
results in this exception:
"
What I did to work around it, is on the select statement, do:
It's pretty ugly, but it works.
当我升级到 cx_Oracle 5.1 后,这些类型的错误就消失了。如果 RPM 没有安装(就像我在 Red Hat 5.5 上发生的那样),那么您通常可以 rpm2cpio 文件,获取 cx_Oracle.so 并将其放入您的 python site-packages 目录中。
These types of errors went away when I upgraded to cx_Oracle 5.1. If the RPM doesn't install (like it happened for me on Red Hat 5.5) then you can usually rpm2cpio the file, take the cx_Oracle.so and put it into your python site-packages directory.
解决方法是将
time.sleep(1)
放在cursor.fetchone()
之前:A work-around is putting
time.sleep(1)
beforecursor.fetchone()
:我有同样的错误。
承诺帮助我:
I had the same error.
Commit helped me: