0% found this document useful (0 votes)
9 views3 pages

DBMS - 17 09

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

DBMS - 17 09

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

4331603 Database Management 236370316009

Practical :- 17
Aim :- Write a program in PL/SQL to show the user of Stored Function.

1
4331603 Database Management 236370316009

Output :-

2
4331603 Database Management 236370316009

Practical :- 17
Aim :- Write a program in PL/SQL to show the user of Stored Function.

Create a simple PL/SQL program with a stored function

-- Create a function that calculates the square of a number

CREATE OR REPLACE FUNCTION calculate_square(p_number IN NUMBER)


RETURN NUMBER
IS
square_result NUMBER;
BEGIN
square_result := p_number * p_number;
RETURN square_result;
END;

-- Create a procedure to demonstrate the usage of the function

CREATE OR REPLACE PROCEDURE demonstrate_stored_function


IS
input_number NUMBER := 5; -- You can change this to any number you want to calculate
the square for
result NUMBER;
BEGIN
-- Call the stored function and store the result in a variable
result := calculate_square(input_number);

-- Display the result

DBMS_OUTPUT.PUT_LINE('The square of ' || input_number || ' is: ' || result);


END;
/
-- Enable output to see the result

SET SERVEROUTPUT ON;


-- Execute the procedure to demonstrate the stored function
EXECUTE demonstrate_stored_function;

You might also like