Home » SQL & PL/SQL » SQL & PL/SQL » Display ratio of 2 numbers
Display ratio of 2 numbers Mon, 25 February 2008 04:05
 sahiti Messages: 9Registered: 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 #302327 is a reply to message #302303] Mon, 25 February 2008 04:39
 skooman Messages: 913Registered: March 2005 Location: Netherlands Senior Member
Are the numbers stored in diffent rows or in different columns?
Re: Display ratio of 2 numbers [message #303140 is a reply to message #302303] Thu, 28 February 2008 02:23
 Flash Messages: 34Registered: February 2008 Member
Different rows or different columns, the higher can be divided by the lower and put in like a ratio... makes sense ?
Re: Display ratio of 2 numbers [message #303206 is a reply to message #303140] Thu, 28 February 2008 06:38
 skooman Messages: 913Registered: March 2005 Location: Netherlands Senior Member
Well, this doesn't make sense to me, but perhaps it does to the OP?
Re: Display ratio of 2 numbers [message #303508 is a reply to message #302303] Fri, 29 February 2008 10:57
 dude4084 Messages: 222Registered: 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
 Previous Topic: Disabling procedures and triggers Next Topic: can procedures created in sql server be converted into oracle (merged)
Goto Forum:

Current Time: Wed Aug 23 16:37:07 CDT 2017

Total time taken to generate the page: 0.09900 seconds