0% found this document useful (0 votes)
46 views

Experiment: Perform Task On Implicit Cursor

1) The student created an EMPLOYEE table with various fields and inserted sample records. 2) An implicit cursor was used to increment the salary of employees with over 2 years of experience, affecting 2 rows. 3) Another cursor inserted a new employee record and displayed the number of rows inserted. 4) A final cursor fetched and displayed employees with over 14 years of experience, showing the number of rows returned.

Uploaded by

Vijay Maurya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Experiment: Perform Task On Implicit Cursor

1) The student created an EMPLOYEE table with various fields and inserted sample records. 2) An implicit cursor was used to increment the salary of employees with over 2 years of experience, affecting 2 rows. 3) Another cursor inserted a new employee record and displayed the number of rows inserted. 4) A final cursor fetched and displayed employees with over 14 years of experience, showing the number of rows returned.

Uploaded by

Vijay Maurya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment: Perform task on implicit cursor

Student Name: Mahesh Sharma                          UID: 21MCI1127

Branch: MCA (AIML)                                                  Section/Group: 21MAM-1/B

Semester: 1st                                                                   Date of Performance: 07/10/2021

Subject Name: PLSQL LAB                                         Subject Code: 21CAP-627

1) Task to be done:

Create the table Employee having ID, Name, Email, Exp, Salary, Phone, Address as their
fields. Write the implicit cursor for the following operations
a) University has given the increment of Rs. 20,000 for those employees who have spent
their 2 years in the University; you have to find out how many rows are affected.
b) Insert the record of the employee and create the cursor for the same.
c) Fetch the records of the employees who have the experience of more than 14 years,
write the cursor to find out how many rows are going to be fetched.
2) Steps for experiment/practical:

To create table named employee:


CREATE TABLE EMPLOYEE(

ID NUMBER,

NAME VARCHAR2(20),

EMAIL VARCHAR2(20),

EXP NUMBER(10),

PHONE NUMBER(10),

SALARY NUMBER(20),

ADDRESS VARCHAR2(20)
);

INSERT INTO EMPLOYEE VALUES(1,'VIJAY','[email protected]',12,923456789,20000,'VARANASI');

INSERT INTO EMPLOYEE


VALUES(2,'MAHESH','[email protected]',14,823456789,60000,'CHANDIGARH');

INSERT INTO EMPLOYEE VALUES(3,'SAURABH','[email protected]',15,623456789,70000,'BANGLORE');

INSERT INTO EMPLOYEE VALUES(4,'RAJLUXMI','[email protected]',4,723456789,40000,'PUNJAB');

To create implicit cursor for incrementing salary of employee

DECLARE
ROW_COUNT NUMBER;
BEGIN
UPDATE EMPLOYEE SET SALARY=SALARY+20000 WHERE EXP>2;
IF SQL%NOTFOUND THEN
DBMS_OUTPUT.PUT_LINE('NO EMPLOYEE WITH EXPERIENCE OF TWO YEARS');
ELSIF SQL%FOUND THEN
ROW_COUNT:=SQL%ROWCOUNT;
DBMS_OUTPUT.PUT_LINE(ROW_COUNT||' EMPLOYEES SALARY INCREEMENTED WITH
20000');
END IF;
END;
SELECT *FROM EMPLOYEE;

To create cursor for inserting employee

DECLARE
R1 NUMBER;
BEGIN
INSERT INTO EMPLOYEE
VALUES(7,'ANOOP','[email protected]',2,9234532112,23000,'GORAKHPUR');
R1 :=SQL%ROWCOUNT;
DBMS_OUTPUT.PUT_LINE( R1 || ' ROW INSERTED ');
END;
SELECT *FROM EMPLOYEE;

To create cursor for fetching employees

DECLARE
E_ID EMPLOYEE.ID%TYPE;
E_NAME EMPLOYEE.NAME%TYPE;
E_MAIL EMPLOYEE.EMAIL%TYPE;
YR EMPLOYEE.EXP%TYPE;
PH EMPLOYEE.PHONE%TYPE;
SALARY EMPLOYEE.SALARY%TYPE;
ADDR EMPLOYEE.ADDRESS%TYPE;
TR NUMBER:=0;
CURSOR DATA2 IS
SELECT ID,NAME,EMAIL,EXP,PHONE,SALARY,ADDRESS FROM EMPLOYEE WHERE
EXP>=14;
BEGIN
OPEN DATA2;
LOOP
FETCH DATA2 INTO E_ID,E_NAME,E_MAIL,YR,PH,SALARY,ADDR;
EXIT WHEN DATA2%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(E_ID || ' ' || E_NAME || ' ' || E_MAIL || ' ' || YR || ' ' || PH || ' ' ||
SALARY || ' ' || ADDR);
TR := TR + 1;
END LOOP;
CLOSE DATA2;
DBMS_OUTPUT.PUT_LINE('NUMBER OF ROWS: '|| TR);
END;

3) Output

 Creating table:-

 Incrementing salary of employee:-


 Output after incrementation:-

 Insert the data through cursor :-

 After insertion table value:-


 Fetch the data from table through implicit coursor:-

4) Learning outcomes (What I have learnt):

1. Learnt to create cursor.

2. Learnt to fetch and update the data using cursor.

3. Learnt to display the rows affected in table by any operation.


Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and Performance 5
(Pre Lab Quiz)
2. Worksheet 10
3. Post Lab Quiz 5

You might also like