Re: [cx-oracle-users] Integers in oracle
Brought to you by:
atuining
|
From: Anthony T. <an...@co...> - 2003-08-28 14:00:40
|
Unfortunately, Oracle declares the "integer" to be without scale and
precision. Internally, cx_Oracle checks the scale and precision to
determine whether or not an integer ought to be returned. Specifically,
if the precision is between 1 and 9 and the scale is 0, an integer is
returned; otherwise, a float is returned.
This has always annoyed me but I don't know a good way around it. Oracle
has a numeric precision exceeding floating point by a great deal so a
while ago I added a "switch" OPT_NumbersAsStrings which, if set, will
return all numbers as strings instead of integers or floating point
numbers. This is useful for retaining the precision of the Oracle
numbers. You could use that, if you wish but it still requires you to
run int() on the result.
I have considered a method for telling cx_Oracle that the values ought
to be returned as integers, ignoring the precision and scale, but I
haven't come up with anything useful yet. Got any suggestions? One
possibility is the following:
vars = cursor.execute("select cast(1 as int) from dual")
vars[0].returntype = cx_Oracle.INTEGER
result, = cursor.fetchone()
Another is:
cursor.define(1, cx_Oracle.INTEGER)
cursor.execute("select cast(1 as int) from dual")
result, = cursor.fetchone()
At this point, result would be an integer. Neither is particularly
pleasant but perhaps better than the current situation. Any thoughts?
On Thu, 2003-08-28 at 04:05, Marcos Sánchez Provencio wrote:
> Why is it that I get 1.0 when I ask for
>
> select cast(1 as int) from dual
> ?
>
> Is this Oracle?, Python?, me?
--
Anthony Tuininga
an...@co...
Computronix
Distinctive Software. Real People.
Suite 200, 10216 - 124 Street NW
Edmonton, AB, Canada T5N 4A3
Phone: (780) 454-3700
Fax: (780) 454-3838
http://www.computronix.com
|