Home » SQL & PL/SQL » SQL & PL/SQL » Display ratio of 2 numbers
Display ratio of 2 numbers [message #302303] Mon, 25 February 2008 04:05 Go to next message
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 #302327 is a reply to message #302303] Mon, 25 February 2008 04:39 Go to previous messageGo to next message
skooman
Messages: 913
Registered: 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 Go to previous messageGo to next message
Flash
Messages: 34
Registered: 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 Go to previous messageGo to next message
skooman
Messages: 913
Registered: 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 Go to previous message
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
Previous Topic: Limiting Number of Duplicates?
Next Topic: Tricky Problem with Connect By
Goto Forum:
  


Current Time: Sat Dec 14 02:13:51 CST 2024