DBMS 9 10 11-1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

DATABASE MANAGEMENT SYSTEM

PRACTICAL 8
AIM:Write a PL/SQL program to demonstrate Cursors

DECLARE

-- Declare variables to hold data from the cursor

emp_id employees.employee_id%TYPE;

emp_name employees.first_name%TYPE;

emp_salary employees.salary%TYPE;

-- Declare a cursor

CURSOR emp_cursor IS

SELECT employee_id, first_name, salary

FROM employees

WHERE department_id = 50;

BEGIN

-- Open the cursor

OPEN emp_cursor;

-- Fetch and process each row from the cursor

LOOP

FETCH emp_cursor INTO emp_id, emp_name, emp_salary;

EXIT WHEN emp_cursor%NOTFOUND; -- Exit the loop if no more rows

-- Display the employee information


SUBMITTED BY TEACHER
SIGN

suhail (22964)
DATABASE MANAGEMENT SYSTEM

DBMS_OUTPUT.PUT_LINE('Employee ID: ' || emp_id);


DBMS_OUTPUT.PUT_LINE('Employee Name: ' || emp_name);

DBMS_OUTPUT.PUT_LINE('Salary: ' || emp_salary);

DBMS_OUTPUT.PUT_LINE('------------------------');

END LOOP;

-- Close the cursor

CLOSE emp_cursor;

END;

OUTPUT

SUBMITTED BY TEACHER
SIGN

suhail (22964)
DATABASE MANAGEMENT SYSTEM

Practical 9
AIM:Write a PL/SQL program to demonstrate Packages.
PL/SQL program that demonstrates the usage of packages. In this example, we'll
create a package with two procedures to calculate the area and circumference of
a circle.

CREATE OR REPLACE PACKAGE circle_package AS

-- Declaration of constants

pi CONSTANT NUMBER := 3.14159;

-- Declaration of procedures

PROCEDURE calculate_area(radius IN NUMBER);

PROCEDURE calculate_circumference(radius IN NUMBER);

END;

CREATE OR REPLACE PACKAGE BODY circle_package AS

-- Implementation of procedures

PROCEDURE calculate_area(radius IN NUMBER) IS

area NUMBER;

BEGIN

area := pi * radius * radius;

DBMS_OUTPUT.PUT_LINE('Area of the circle: ' || area);

END;

PROCEDURE calculate_circumference(radius IN NUMBER) IS

circumference NUMBER;

SUBMITTED BY TEACHER
SIGN
suhail (22964)

DATABASE MANAGEMENT SYSTEM

BEGIN

circumference := 2 * pi * radius;

DBMS_OUTPUT.PUT_LINE('Circumference of the circle: ' || circumference);

END;

END;

OUTPUT

SUBMITTED BY TEACHER
SIGN

suhail (22964)
DATABASE MANAGEMENT SYSTEM

PRACTICAL 10
AIM:Write PL/SQL queries to create Procedures

DECLARE

emp_name VARCHAR2(100);

emp_salary NUMBER;

BEGIN

-- Call the insert_employee procedure

insert_employee(1, 'John Doe', 5000);

-- Call the get_employee_info procedure

get_employee_info(1, emp_name, emp_salary);

-- Display the retrieved employee information

DBMS_OUTPUT.PUT_LINE('Employee Name: ' || emp_name);

DBMS_OUTPUT.PUT_LINE('Employee Salary: ' || emp_salary);

END;

SUBMITTED BY TEACHER
SIGN
suhail (22964)

DATABASE MANAGEMENT SYSTEM

PRACTICAL 11
AIM:Write PL/SQL queries to create Triggers.

CREATE OR REPLACE TRIGGER display_salary_changes

BEFORE DELETE OR INSERT OR UPDATE ON customers

FOR EACH ROW

WHEN (new.id > 0)

DECLARE

sal_diff NUMBER;

BEGIN

sal_diff := :NEW.salary - :OLD.salary;

dbms_output.put_line('Old salary: ' || :OLD.salary);

dbms_output.put_line('New salary: ' || :NEW.salary);

dbms_output.put_line('Salary difference: ' || sal_diff);

END;

output

SUBMITTED BY TEACHER
SIGN
suhail (22964)

DATABASE MANAGEMENT SYSTEM

PRACTICAL-12
AIM: Draw an ER Diagram for inventory management system.
a) Mention all required entities and their attributes
b) Mention all key constraints
c) Mention all relationship in the diagram

SUBMITTED BY TEACHER
SIGN

suhail (22964)
DATABASE MANAGEMENT SYSTEM

PRACTICAL-13
AIM: Draw an ER Diagram for flight reservation system.
a) Mention all required entities and their attributes
b) Mention all key constraints
c) Mention all relationship in the diagram

SUBMITTED BY TEACHER
SIGN

suhail (22964

You might also like