Experiment: Perform Task On Implicit Cursor
Experiment: Perform Task On Implicit Cursor
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:
ID NUMBER,
NAME VARCHAR2(20),
EMAIL VARCHAR2(20),
EXP NUMBER(10),
PHONE NUMBER(10),
SALARY NUMBER(20),
ADDRESS VARCHAR2(20)
);
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;
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;
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:-