--> 1 STATE THE OUTPUT
DECLARE
CURSOR C1 IS SELECT * FROM EMP WHERE SAL=7000;
EMP_REC C1%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('NAME SALARY');
FOR EMP_REC.SAL:=7000
DBMS_OUTPUT.PUT_LINE(EMP_REC.ENAME||' '||EMP_REC.SAL);
END LOOP;
END;
--> 2 STATE THE OUTPUT
DECLARE
V_NO emp.empno%TYPE:=V_NO;
V_NAME EMP.ENAME%TYPE;
V_DESIGNATION EMP.JOB%TYPE;
V_SAL EMP.SAL%TYPE;
BEGIN
SELECT ENAME,SAL,JOB INTO V_NAME,V_SAL,V_DESIGNATION FROM EMP WHERE EMP.EMPNO=V_NO;
IF SQL%FOUND THEN
DBMS_OUTPUT.PUT_LINE(V_NAME||' ' ||V_SAL||' '||V_DESIGNATION);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('EMPLOYEE DOES NOT EXITS');
END;
--> TO PRINT FIRST 5 HIGHEST SALARY EARNER EMPLOYEE
DECLARE
I INT:=0;
CURSOR C1 IS SELECT ENAME,SAL FROM EMP ORDER BY SAL DESC ;
BEGIN
FOR R IN C1
LOOP
EXIT WHEN I>5;
DBMS_OUTPUT.PUT_LINE(R.ENAME||' '||R.SAL);
I:=I+1;
END LOOP;
END;
DECLARE
CURSOR C1 IS SELECT * FROM EMP WHERE SAL=7000;
EMP_REC C1%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('NAME SALARY');
FOR EMP_REC.SAL:=7000
DBMS_OUTPUT.PUT_LINE(EMP_REC.ENAME||' '||EMP_REC.SAL);
END LOOP;
END;
--> 2 STATE THE OUTPUT
DECLARE
V_NO emp.empno%TYPE:=V_NO;
V_NAME EMP.ENAME%TYPE;
V_DESIGNATION EMP.JOB%TYPE;
V_SAL EMP.SAL%TYPE;
BEGIN
SELECT ENAME,SAL,JOB INTO V_NAME,V_SAL,V_DESIGNATION FROM EMP WHERE EMP.EMPNO=V_NO;
IF SQL%FOUND THEN
DBMS_OUTPUT.PUT_LINE(V_NAME||' ' ||V_SAL||' '||V_DESIGNATION);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('EMPLOYEE DOES NOT EXITS');
END;
--> TO PRINT FIRST 5 HIGHEST SALARY EARNER EMPLOYEE
DECLARE
I INT:=0;
CURSOR C1 IS SELECT ENAME,SAL FROM EMP ORDER BY SAL DESC ;
BEGIN
FOR R IN C1
LOOP
EXIT WHEN I>5;
DBMS_OUTPUT.PUT_LINE(R.ENAME||' '||R.SAL);
I:=I+1;
END LOOP;
END;