# 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
```

TOP Interview Coding Problems/Challenges

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates