SET SERVEROUTPUT ON
DECLARE
--Cursor declaration
CURSOR C_EMP is
SELECT INITCAP(ename),
(CASE
WHEN sal + nvl(comm,0) > 4000 THEN 'High Earning'
WHEN sal + nvl(comm,0) BETWEEN 2000 AND 3999 THEN 'Medium Earning'
ELSE 'Low Earning'
END) Earning
FROM emp;
--TYPE declaration
TYPE emp_salary_info IS RECORD
(name emp.ename%TYPE,
earning VARCHAR2(20));
--Variable declaration
v_emp_sal_info emp_salary_info;
BEGIN
-- open cursor
OPEN C_EMP;
LOOP
-- fetch cursor
FETCH C_EMP INTO v_emp_sal_info;
EXIT WHEN C_EMP%NOTFOUND;
IF C_EMP%ROWCOUNT = 1 THEN
DBMS_OUTPUT.PUT_LINE( 'ENAME'||'---->'||'EARNING DETAIL' );
END IF;
DBMS_OUTPUT.PUT_LINE( v_emp_sal_info.name||'---->'||v_emp_sal_info.earning);
END LOOP;
--close cursor
CLOSE C_EMP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data found exception raised');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Others Exception raised');
IF C_EMP%ISOPEN THEN
CLOSE C_EMP;
END IF;
END;
anonymous block completed
ENAME---->EARNING DETAIL
Smith---->Low Earning
Allen---->Low Earning
Ward---->Low Earning
Jones---->Medium Earning
Martin---->Medium Earning
Blake---->Medium Earning
Clark---->Medium Earning
Scott---->Medium Earning
King---->High Earning
Turner---->Low Earning
Adams---->Low Earning
James---->Low Earning
Ford---->Medium Earning
Miller---->Low Earning
Subscribe to:
Post Comments (Atom)
External Table
Oracle External Table External tables are defined as tables that do not resides in the database allows you to access data that is stor...
-
Table clustering is an optional technique of storing data. In table clustering, rows from one or more tables those are associated with ea...
-
Oracle PL/SQL block accepts user input information with the help of substitution variable. Substitute variable can not be used to output va...
-
Finally continue statement added to oracle 11g PL/SQL language. It signals an immediate end to a loop iteration and return to first statemen...
No comments:
Post a Comment