/*Fetch Every Employee Details With the help of cursor*/
/*DBMS:SCOTT/TIGER:ORACLE 9i*/
SET SERVEROUTPUT ON
DECLARE
VEMPNO EMP.EMPNO%TYPE;
VENAME EMP.ENAME%TYPE;
VSAL EMP.SAL%TYPE;
CURSOR CR_EMP
IS
SELECT EMPNO,ENAME,SAL FROM EMP;
BEGIN
OPEN CR_EMP;
LOOP
FETCH CR_EMP INTO VEMPNO,VENAME,VSAL;
EXIT WHEN CR_EMP%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('EMPLOYEE DETAILS');
DBMS_OUTPUT.PUT_LINE('----------------');
DBMS_OUTPUT.PUT_LINE('ID: '||VEMPNO);
DBMS_OUTPUT.PUT_LINE('NAME: '||VENAME);
DBMS_OUTPUT.PUT_LINE('BASIC: '||VSAL);
DBMS_OUTPUT.PUT_LINE('----------------');
END LOOP;
CLOSE CR_EMP;
END;
OR
/*Fetch Every Employee Details With the help of cursor*/
/*DBMS:SCOTT/TIGER:ORACLE 9i*/
/*WHILE LOOP*/
SET SERVEROUTPUT ON
DECLARE
VEMPNO EMP.EMPNO%TYPE;
VENAME EMP.ENAME%TYPE;
VSAL EMP.SAL%TYPE;
CURSOR CR_EMP
IS
SELECT EMPNO,ENAME,SAL FROM EMP;
BEGIN
OPEN CR_EMP;
FETCH CR_EMP INTO VEMPNO,VENAME,VSAL;
WHILE CR_EMP%FOUND
LOOP
EXIT WHEN CR_EMP%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('EMPLOYEE DETAILS');
DBMS_OUTPUT.PUT_LINE('----------------');
DBMS_OUTPUT.PUT_LINE('ID: '||VEMPNO);
DBMS_OUTPUT.PUT_LINE('NAME: '||VENAME);
DBMS_OUTPUT.PUT_LINE('BASIC: '||VSAL);
DBMS_OUTPUT.PUT_LINE('-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-');
END LOOP;
END;
/*CALCULATE SUM OF TOTAL OF SALARY WHOSE INCOME LESS THAN 1000 USING CURSOR
/*ORACLE 9i
/* PREDEFINED DATABASE := SCOTT/TIGER*/
SET SERVEROUTPUT ON
DECLARE
VSUM_TL NUMBER:=0;
VSAL NUMBER:=0;
VENAME EMP.ENAME%TYPE;
CURSOR T1 IS SELECT ENAME,SAL FROM EMP ORDER BY SAL;
BEGIN
OPEN T1;
LOOP
FETCH T1 INTO VENAME,VSAL;
EXIT WHEN NOT T1%FOUND;
IF VSAL<=1500 THEN
DBMS_OUTPUT.PUT_LINE(VENAME || ' : ' || VSAL);
VSUM_TL := VSUM_TL + VSAL;
END IF;
END LOOP;
DBMS_OUTPUT.PUT_LINE('----------------');
DBMS_OUTPUT.PUT_LINE(' ' || VSUM_TL);
CLOSE T1;
END;
Comments
Post a Comment