Home » SQL & PL/SQL » SQL & PL/SQL » Urgent:Please Help
Urgent:Please Help [message #192963] Thu, 14 September 2006 07:16 Go to next message
AnilOrafaq
Messages: 12
Registered: May 2006
Junior Member
I've requirement as below.

I've 5 expressions which needs to find out which is the greatest expression among the 5.

Assume,

and if i write select stmt in a pl/sql block

declare
a number:=5;
b number:=10;
c number:=2;
d number:=7;
e number:=40;
temp number;
begin
Select Greatest(a,b,c,d,e) into temp from dual;
--now the temp variable hold the greatest value among the five
--But,i want to find the variable greast among.
--Do we any oracle built-in fuction to cater the same or
--i need to write a routine to do the same
end;

please revert with your answers.

Thanks,Anil
Re: Urgent:Please Help [message #192967 is a reply to message #192963] Thu, 14 September 2006 07:21 Go to previous message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
(Very) quick and dirty:
set serverout on

DECLARE
  a      NUMBER := 5;
  b      NUMBER := 10;
  c      NUMBER := 2;
  d      NUMBER := 7;
  e      NUMBER := 40;
  temp   NUMBER;
BEGIN
  temp    := GREATEST (a, b, c, d, e);

  CASE temp
    WHEN a
    THEN
      DBMS_OUTPUT.put_line ('Variable a holds the greatest value: '||temp);
    WHEN b
    THEN
      DBMS_OUTPUT.put_line ('Variable b holds the greatest value: '||temp);
    WHEN c
    THEN
      DBMS_OUTPUT.put_line ('Variable c holds the greatest value: '||temp);
    WHEN d
    THEN
      DBMS_OUTPUT.put_line ('Variable d holds the greatest value: '||temp);
    WHEN e
    THEN
      DBMS_OUTPUT.put_line ('Variable e holds the greatest value: '||temp);
  END CASE;
END;
/


How would you handle equal values?
MHE
Previous Topic: HOW TO: Create clone user in oracle
Next Topic: end-of-file Communication channel
Goto Forum:
  


Current Time: Thu Dec 08 10:21:48 CST 2016

Total time taken to generate the page: 0.08234 seconds