admin管理员组文章数量:1418690
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
本文标签: sqldata type changes when using AVG in view definitionStack Overflow
版权声明:本文标题:sql - data type changes when using AVG in view definition - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745293926a2651962.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