0% found this document useful (0 votes)
0 views2 pages

PLSQL Practicals

The document contains practical PL/SQL programs demonstrating variable declaration, checking if a number is even or odd, finding the greatest of three numbers, calculating the factorial of a number, and creating a trigger to modify employee salary upon insertion. Each program is structured with a DECLARE and BEGIN block, showcasing different functionalities. These examples serve as fundamental exercises for understanding PL/SQL programming.

Uploaded by

varunisbet12345
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)
0 views2 pages

PLSQL Practicals

The document contains practical PL/SQL programs demonstrating variable declaration, checking if a number is even or odd, finding the greatest of three numbers, calculating the factorial of a number, and creating a trigger to modify employee salary upon insertion. Each program is structured with a DECLARE and BEGIN block, showcasing different functionalities. These examples serve as fundamental exercises for understanding PL/SQL programming.

Uploaded by

varunisbet12345
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

PL/SQL Practical Programs

1. Declaration of Variables
DECLARE
num NUMBER := 10;
name VARCHAR2(20) := 'Varun';
BEGIN
DBMS_OUTPUT.PUT_LINE('Number: ' || num);
DBMS_OUTPUT.PUT_LINE('Name: ' || name);
END;
/

2. Even or Odd
DECLARE
num NUMBER := 7;
BEGIN
IF MOD(num,2) = 0 THEN
DBMS_OUTPUT.PUT_LINE('Even Number');
ELSE
DBMS_OUTPUT.PUT_LINE('Odd Number');
END IF;
END;
/

3. Greatest of Three Numbers


DECLARE
a NUMBER := 10;
b NUMBER := 25;
c NUMBER := 15;
BEGIN
IF a > b AND a > c THEN
DBMS_OUTPUT.PUT_LINE(a);
ELSIF b > c THEN
DBMS_OUTPUT.PUT_LINE(b);
ELSE
DBMS_OUTPUT.PUT_LINE(c);
END IF;
END;
/

4. Factorial
DECLARE
n NUMBER := 5;
fact NUMBER := 1;
BEGIN
FOR i IN 1..n LOOP
fact := fact * i;
END LOOP;
DBMS_OUTPUT.PUT_LINE(fact);
END;
/

5. Trigger Example
CREATE OR REPLACE TRIGGER emp_trigger
BEFORE INSERT ON employees
FOR EACH ROW
BEGIN
:[Link] := :[Link] + 500;
END;
/

You might also like