PLsql cursor, procedure,trigger

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

Database Schema

Use the following tables for this assignment:

1. Employees Table

CREATE TABLE Employees (

EmpID NUMBER PRIMARY KEY,

Name VARCHAR2(50),

Department VARCHAR2(50),

Salary NUMBER

);

2. Audit Table

CREATE TABLE Salary_Audit (

AuditID NUMBER PRIMARY KEY,

EmpID NUMBER,

OldSalary NUMBER,

NewSalary NUMBER,

UpdatedBy VARCHAR2(50),

UpdatedOn DATE

);

Tasks

1. Cursor

Write a PL/SQL block that:

 Uses a cursor to fetch employee details (Name and Salary) whose salaries exceed a specified
value.

 Displays these details using DBMS_OUTPUT.

Example Output:

Employee: John, Salary: 60000

Employee: Alice, Salary: 80000

2. Trigger

Create a trigger on the Employees table that:


 Logs changes to employee salaries in the Salary_Audit table whenever an update occurs.

 Includes fields such as the old salary, new salary, employee ID, user updating the record, and
the timestamp.

3. Procedure

Create a stored procedure that:

 Transfers an employee from one department to another.

 Accepts the following parameters:

o Employee ID (EmpID)

o New Department Name (NewDept)

 Updates the department in the Employees table and prints a confirmation message.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy