This content has been marked as final. Show 4 replies
Since I don't know what you are trying to do, or how you coded it, here's once reference: glance at the input/output handler section in http://www.oracle.com/technetwork/articles/tuininga-cx-oracle-084866.html
i have seen the document you referenced.
this is what i'm trying to do:
SQL> select volume from goods; VOLUME ------ 0.088 1 row selected (python/cx_Oracle) cur.execute("select volume from goods") rows = cur.fetchall() rows [(0.08800000000000001,)] v = 0.088 v 0.088
the value stored in the DB has been set to precision 0.3f, and
sqlplus returns it as-is.
in python/cx_Oracle, the value is 0.08800000000000001.
the example shows what is typed at the interpreter, and also
in python scripts (outside of cx_Oracle).
assignments keep the precision specified.
is there a way to get the same behaviour ?
What about using one of these:
# t.py import cx_Oracle import decimal db = cx_Oracle.connect("cj", "cj", "localhost/orcl") cur = db.cursor() cur.execute("select volume from goods") rows = cur.fetchall() print rows cur = db.cursor() cur.execute("select to_char(volume) from goods") rows = cur.fetchall() print rows print float(rows) def NumbersAsDecimal(cursor, name, defaultType, size, precision, scale): if defaultType == cx_Oracle.NUMBER: return cursor.var(str, 100, cursor.arraysize, outconverter = decimal.Decimal) db.outputtypehandler = NumbersAsDecimal cur = db.cursor() cur.execute("select volume from goods") rows = cur.fetchall() print rows
$ python t.py [(0.08800000000000001,)] [('.088',)] 0.088 [(Decimal('0.088'),)]
thank you very much for your suggestions!
i cannot use the to_char/string solutions,
because we need to be able to sort the data
i used the decimal solution you proposed,
and that resolved the problem.
the next problem i ran into, was that
json was not able to serialize decimal types.
came across the following at:
which help with the floats ...
(sorry for the lapse and lateness in reply,
was testing and adapting the solution.. and
then worked on another issue)
Thanks again! you've been a great help!