Question: Question 2 : PL / SQL Bulk Insert Based on HR Employees Objective: The goal of this assignment is to create a PL / SQL
Question : PLSQL Bulk Insert Based on HR Employees
Objective:
The goal of this assignment is to create a PLSQL program that demonstrates the use of bulk
operations to efficiently insert multiple records into a table using data from the HREMPLOYEES
table. The student will practice PLSQL concepts such as cursors, bulk collect, and bulk insert.
Problem Statement:
You are tasked with creating a PLSQL procedure that performs a bulk insert of employee records
from the HREMPLOYEES table into a new table EMPLOYEEARCHIVE. The bulk insert should be
efficient, using PLSQL features such as cursors and bulk collect.
Steps:
Create a new table EMPLOYEEARCHIVE:
o The EMPLOYEEARCHIVE table should have the same structure as the
HREMPLOYEES table but should only include the following columns:
EMPLOYEEID NUMBER
FIRSTNAME VARCHAR
LASTNAME VARCHAR
HIREDATE DATE
SALARY NUMBER
o Use the following SQL statement to create the table:
CREATE TABLE EMPLOYEEARCHIVE
EMPLOYEEID NUMBER
FIRSTNAME VARCHAR
LASTNAME VARCHAR
HIREDATE DATE,
SALARY NUMBER
;
Write a PLSQL Procedure to Perform Bulk Insert:
o Create a PLSQL procedure called BULKINSERTEMPLOYEES.
o The procedure should use a cursor to select employee data from the
HREMPLOYEES table.
o The selected records should be inserted into the EMPLOYEEARCHIVE table using
bulk collect and a FORALL statement for bulk insertion.
Requirements:
o The cursor should retrieve employees whose salary is greater than a specific
threshold eg
o Use BULK COLLECT to fetch the data into a PLSQL collection.
o Use the FORALL statement to insert the records into EMPLOYEEARCHIVE.
o Include exception handling to catch any errors during the bulk insert.
Hints:
o You may use BULK COLLECT and LIMIT to fetch rows in batches if needed.
o Use a FORALL loop to perform the insertions in bulk.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
