Display ratio of 2 numbers [message #302303] |
Mon, 25 February 2008 04:05 |
sahiti
Messages: 9 Registered: November 2007 Location: India
|
Junior Member |
|
|
Hi All,
I need to find the ratio of 2 numbers and display it in a report.
How to do it
Can anyone tell me is there any predefined function to find this
or is there anyway to do it in oracle discoverer.
say for example the numbers are 160,80
i need to display thee ratio as 2:1
Thanks in advance
|
|
|
|
|
|
Re: Display ratio of 2 numbers [message #303508 is a reply to message #302303] |
Fri, 29 February 2008 10:57 |
dude4084
Messages: 222 Registered: March 2005 Location: Mux
|
Senior Member |
|
|
Hi
This can be done with the help of function.
I have tried to find the solution by creating function as follow:
create or replace function myratio
(pin_a IN NUMBER,
pin_b IN NUMBER) RETURN CHAR IS
a NUMBER := pin_a;
b NUMBER := pin_b;
j NUMBER := 2;
ulimit number := least(a,b);
ans varchar2(30);
BEGIN
loop
if mod(a, j)= 0 then
if mod(b, j)= 0 then
a:=a/j;
b:=b/j;
j:=1;
end if;
end if;
j:=j+1;
exit when j >ulimit;
END loop;
RETURN (to_char(a) ||', '|| to_char(b));
end;
/
The execution and result of the function is as follow:
Quote: | select myratio(160,80)
from dual;
MYRATIO(160,80)
----------------
2, 1
|
Hence your required solution.
-Dude
|
|
|