1) 找到最近2的n次幂数

declare
params int :=125;
n int:=0;
snum int;
lnum int;
begin


loop
lnum:=power(2,n);
snum:=power(2,n-1);
if lnum>params then
if(lnum-params)>(params-snum) then
dbms_output.put_line(snum);
else
dbms_output.put_line(lnum);
end if;
end if;
exit when lnum>params;
n:=n+1;
end loop;
end;

别人写的

select
max(case when p<=100 then p else null end) as num1,
min(case when p>=100 then p else null end) as num2
from
(select power(2,rownum) as p from dual connect by level <=30)


 

posted on 2020-02-01 11:22  我有我的信仰  阅读(82)  评论(0)    收藏  举报