PLSQL Lab Programs-Dbms
PLSQL Lab Programs-Dbms
SQL> BEGIN
2 DECLARE
3 numerator NUMBER := 10;
4 denominator NUMBER := 0;
5 result NUMBER;
6 BEGIN
7 result:= numerator / denominator;
8 DBMS_OUTPUT.PUT_LINE('Result: ' || result);
9 EXCEPTION
10 WHEN ZERO_DIVIDE THEN
11 DBMS_OUTPUT.PUT_LINE('Error: Division by zero');
12 END;
13 END;
14 /
Output:
Error: Division by zero
Output:
14customers
OUTPUT:
Function created.
SQL> DECLARE
2 num NUMBER;
3 result NUMBER;
4 BEGIN
5 num := 5;
6 result := factorial(num);
7 DBMS_OUTPUT.PUT_LINE('Factorial of ' || num || ' is ' || result);
8 END;
9 /
OUTPUT:
Factorial of 5 is 120
Package created.
SQL> DECLARE
2 -- Declare variables to store results
3 sum_result NUMBER;
4 product_result NUMBER;
5 BEGIN
6 -- Call the procedure and pass output parameter
7 math_operations.add_numbers(5, 7, sum_result);
8 -- Display the result of the add_numbers procedure
9 DBMS_OUTPUT.PUT_LINE('Sum Result: ' || sum_result);
10
11 -- Call the function and retrieve the result
12 product_result := math_operations.multiply_numbers(3, 4);
13 -- Display the result of the multiply_numbers function
14 DBMS_OUTPUT.PUT_LINE('Product Result: ' || product_result);
15 END;
16 /
OUTPUT:
Sum Result: 12
Product Result: 12