|
REMAINDER m-(m/n)*n ; (m/n)4舍6入,5取偶。当(m/n)为x.5的时候,取最接近m/n的偶数
下面为验证代码:
declare
num1 number;
num2 number:=&4;
out1 number:=1;
out2 number:=3;
i number;
erro exception;
begin
i:=1;
while i<=10000 loop
i:=i+1;
num1:=i;
SELECT remainder(num1, num2) into out1
FROM duaL;
select num1 - (case
when substr(col, instr(col, '.')) = '.5' and
mod(floor(col), 2) = 0 then
floor(col)
else
round(col)
end) * num2 into out2
from (select num1 / num2 col from dual);
if nvl(out1,'1')<>nvl(out2,'2') then
raise erro;
end if;
end loop;
DBMS_OUTPUT.put_line ( num1||'-'||num2||'-'||out1||'-'||out2);
exception
when erro then
raise_application_error(-20000,num1||'-'||num2||'-'||out1||'-'||out2,TRUE);
RAISE;
when others then
raise_application_error(-20000,num1||'-'||num2||'-'||out1||'-'||out2,TRUE);
RAISE;
end;
|
|