SQL program to create functions for finding greatest of three numbers


FUNCTIONS
AIM:
  To write a mysql program to create functions for finding greatest of three numbers.

 ALGORITHM:
 
            Step 1:  Start the program
Step 2. Create a function named greatest with 3 input aruguments a,b,c and output
            argument  as g
            Step 3 .If a is greater than b and c then  assign to g else check if b is greater than
                        assign 0 to g
Step 4 .Return the value of g.
Step 5. Stop the program


PROGRAM:

SQL> create or replace function greater (a in number,b in number,c in number)return number is g numbers
            2  begin
            3  if (a>b) then
            4  g:=a;
            5  else
            6  g:=b;
            7  if(c>g)then
            8  g:=c;
            9  end if;
            10  end if;
            11  return(g);
            12  end;
            13  /

            Function created

SQL> declare a number(3);
            2  b number(3);
            3  c number(3);
            4  d number(3);
             5  begin
            6  a:=&a;
            7  b:=&b;
            8  c:=&c;
            9  d:=greater(a,b,c);
            10  dbms_output.put_line(d);
            11  end;
            12  /

OUTPUT:
Enter value for a: 45
old   6: a:=&a;
new   6: a:=45;
Enter value for b: 35
old   7: b:=&b;
new   7: b:=35;
Enter value for c: 25
old   8: c:=&c;
new   8: c:=25;
45

SQL  procedure successfully completed.

0 comments:

Post a Comment