0% found this document useful (0 votes)
45 views

Begin: IN & OUT Mode Example 2

This document contains examples of using procedures and functions in PL/SQL. It demonstrates using IN, OUT, and IN OUT parameters. The first procedure finds the minimum of two numbers and outputs it. The second procedure squares a number passed using IN OUT. The function finds the maximum of two numbers and returns the value.

Uploaded by

srividhya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Begin: IN & OUT Mode Example 2

This document contains examples of using procedures and functions in PL/SQL. It demonstrates using IN, OUT, and IN OUT parameters. The first procedure finds the minimum of two numbers and outputs it. The second procedure squares a number passed using IN OUT. The function finds the maximum of two numbers and returns the value.

Uploaded by

srividhya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

DECLARE

a number;
b number;
c number;
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;
BEGIN
a:= 23;
b:= 45;
findMin(a, b, c);
dbms_output.put_line(' Minimum of (23, 45) : ' || c);
END;
/

When the above code is executed at the SQL prompt, it produces the following result −
Minimum of (23, 45) : 23

PL/SQL procedure successfully completed.

IN & OUT Mode Example 2


This procedure computes the square of value of a passed value. This example shows
how we can use the same parameter to accept a value and then return another result.

DECLARE
a number;
PROCEDURE squareNum(x IN OUT number) IS
BEGIN
x := x * x;
END;
BEGIN
a:= 23;
squareNum(a);
dbms_output.put_line(' Square of (23): ' || a);
END;
/

When the above code is executed at the SQL prompt, it produces the following result −
Square of (23): 529

PL/SQL procedure successfully completed.


DECLARE
a number;
b number;
c number;
FUNCTION findMax(x IN number, y IN number)
RETURN number
IS
z number;
BEGIN
IF x > y THEN
z:= x;
ELSE
Z:= y;
END IF;
RETURN z;
END;
BEGIN
a:= 23;
b:= 45;
c := findMax(a, b);
dbms_output.put_line(' Maximum of (23,45): ' || c);
END;
/

When the above code is executed at the SQL prompt, it produces the following result −
Maximum of (23,45): 45

PL/SQL procedure successfully completed.


Procedure Function

 Used mainly to a execute certain


 Used mainly to perform some calculation
process

 A Function that contains no DML statements


 Cannot call in SELECT statement
can be called in SELECT statement

 Use OUT parameter to return the


 Use RETURN to return the value
value

 It is mandatory to return the value


 It is not mandatory to return the
Procedure Function

value

 RETURN will simply exit the control  RETURN will exit the control from
from subprogram. subprogram and also returns the value

 Return datatype will not be  Return datatype is mandatory at the time of


specified at the time of creation creation

You might also like