I have a table with a column of FLOAT data type. Based on this table, I create a view which returns AVG of that column.
create table my_tab (oo float);
create or replace view my_view (oo) as select avg(oo) from my_tab;
describing the view
desc my_view;
will return
Name Null? Type
OO NUMBER
If this an Oracle bug? Can I force somehow to maintain the source data type?
Thank you,
I have a table with a column of FLOAT data type. Based on this table, I create a view which returns AVG of that column.
create table my_tab (oo float);
create or replace view my_view (oo) as select avg(oo) from my_tab;
describing the view
desc my_view;
will return
Name Null? Type
OO NUMBER
If this an Oracle bug? Can I force somehow to maintain the source data type?
Thank you,
Share Improve this question asked Jan 29 at 13:49 mikcutumikcutu 1,0922 gold badges19 silver badges38 bronze badges 1 |1 Answer
Reset to default 1It is not necessarily a bug as it tries to be more precise using Number.
In the documentation it says :
A subtype of the NUMBER data type having precision p. A FLOAT value is represented internally as NUMBER.
Few other supporting docs.
You can still cast it to float as below :
create or replace view my_view (oo) as
select cast(avg(oo) as float) from my_tab;
Fiddle
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745293927a4621026.html
Float
is a subtype ofnumber
- it's justnumber
with different semantics, whereby you specify the precision in in binary bits rather than decimal digits and with different limits. But the internal storage is the same. Whatever you can represent withfloat
can be represented withnumber
. All the aggregation functions (SUM, AVG, etc.) result in the supertypenumber
when fedfloat
. I personally haven't yet found any particular reason to use any numeric dataype other than simplynumber
, except forinteger
as a short-hand way of setting the precision constraint(*,0)
. – Paul W Commented Jan 29 at 14:20