Sokrates on Oracle

select the scale of a number

Posted by Matthias Rogel on 10. August 2012

with qs as
(
select
round(
dbms_random.value(-20, 20),
dbms_random.value(1, 15)
) q
from dual
connect by level<=10
)
select
qs.q,
case
when qs.q = floor(qs.q) then
0
when qs.q is null then null
else
(
select max(level)
from dual
connect by round(qs.q, level - 1) != qs.q
)
end as "scale(q)"
from qs
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: