Home » PL/SQL

Procedure in PL/SQL to find minimum of 2 numbers

Here, we are going to learn how to write a Procedure in PL/SQL to find minimum of 2 numbers?
Submitted by Ayush Sharma, on December 07, 2018

Given two numbers and we have to find the minimum of 2 numbers in PL/SQL.

Syntax:

    
    Create Procedure Procedure-name 
    (
    Input parameters ,
    Output Parameters (If required)
    )
    As
    Begin
         Sql statement used in the stored procedure
    End
    
    END;

The following procedure in SQL is used to find the minimum of two input numbers.

The following lines of SQL code creates a procedure having parameters x, y and z all of them being number type.

In denotes that the variables are used for taking input while out denotes the output.

CREATE OR REPLACE PROCEDURE findMin(x in number,y in number,z out number)

is 

begin
if x<y then
z:=x;
else
z:=y;
end if;
end;

Now to run the procedure we use the following piece of code in sql.

Here a b and c are three number variables which are passed into the findMin function.

code

declare 
a number;
b number;
c number;
begin
a:=23;
b:=45;
findMin(a,b,c);
dbms_output.put_line('MINIMUM'||c);
end; 

Output

23


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.