Difference between Explicit cursor and Ref Cursor



EMPNO
ENAME
HIREDATE
DOB
GENDER
SAL
DEPTNO
JOB
1000
Sachin
11-Sep-85
01-Mar-20
M
25000
20
MANAGER
1002
Rena
01-Aug-82
11-Mar-20
F
125000
20

1008
Sonu
11-Sep-85
01-Mar-20
M
2500
10
CLERK
1003
Chavi
25-Mar-81
15-Feb-20
F
5000
20
CLERK
1006
Ravi
11-Sep-89
01-Mar-19
M
2500
10
CLERK
1005
Vinod
18-Sep-86
01-Mar-20
M
17000
30
DEVELOPER
1004
Rani
28-Jan-88
19-Jul-19
F
27000
30
MANAGER
1007
Manoj
11-Sep-85
09-Mar-18
M
18000
10
DEVELOPER
1001
Amit
11-Sep-80
01-Jan-20
M
10000
40
DEVELOPER
1009
Nitin Kumar
11-Sep-85
11-Mar-20
M
21000
20
DEVELOPER


--====================================================
--Ref Explicit Cursor
--====================================================

DECLARE
  v_name XX_EMP_TL.ENAME%TYPE;

  CURSOR C1 IS 
  SELECT ename FROM XX_EMP_TL ;

    BEGIN     
        OPEN C1;
            LOOP               
                FETCH C1 INTO v_name;
                EXIT WHEN C1%NOTFOUND;                                
                 DBMS_OUTPUT.PUT_LINE (C1%ROWCOUNT||' - '||v_name);
                   
            END LOOP;
           
        CLOSE C1;     
    END;


--====================================================
--Ref Explicit Cursor
--====================================================



DECLARE

VAR_1 VARCHAR2(100);
VAR_2 NUMBER;

  CURSOR C_EMP IS 
  SELECT ename, sal FROM XX_EMP_TL ;

  CURSOR C_DEPT IS 
  SELECT DNAME, DEPTNO FROM XX_DEPT_TL ;

    BEGIN
    dbms_output.put_line ('************** EMPLOYEE DETAILS****************');     
        OPEN C_EMP;
            LOOP               
                FETCH C_EMP INTO VAR_1, VAR_2;
                EXIT WHEN C_EMP%NOTFOUND;                                
                 DBMS_OUTPUT.PUT_LINE (C_EMP%ROWCOUNT||' - '||VAR_1||' | salary is :- '||VAR_2);                   
            END LOOP;           
        CLOSE C_EMP;     
       
        dbms_output.put_line ('************** DEPARTMENT DETAILS****************');
        OPEN C_DEPT;
            LOOP               
                FETCH C_DEPT INTO VAR_1, VAR_2;
                EXIT WHEN C_DEPT%NOTFOUND;                                
                 DBMS_OUTPUT.PUT_LINE (C_DEPT%ROWCOUNT||' - '||VAR_1||' | Location is :- '||VAR_2);                   
            END LOOP;           
        CLOSE C_DEPT;
       
    END;




--====================================================
--Ref  Cursor
--====================================================


DECLARE

Type XX_REF_CUR_TYPE IS REF CURSOR;

C_REF XX_REF_CUR_TYPE;

VAR_1 VARCHAR2(100);
VAR_2 NUMBER;
 
    BEGIN
    dbms_output.put_line ('************** EMPLOYEE DETAILS****************');     
        OPEN C_REF FOR  SELECT ename, sal FROM XX_EMP_TL ;
            LOOP               
                FETCH C_REF INTO VAR_1, VAR_2;
                EXIT WHEN C_REF%NOTFOUND;                                
                 DBMS_OUTPUT.PUT_LINE (C_REF%ROWCOUNT||' - '||VAR_1||' | salary is :- '||VAR_2);                   
            END LOOP;           
        CLOSE C_REF;     
       
        dbms_output.put_line ('************** DEPARTMENT DETAILS****************');
        OPEN C_REF FOR SELECT DNAME, DEPTNO FROM XX_DEPT_TL;
            LOOP               
                FETCH C_REF INTO VAR_1, VAR_2;
                EXIT WHEN C_REF%NOTFOUND;                                
                 DBMS_OUTPUT.PUT_LINE (C_REF%ROWCOUNT||' - '||VAR_1||' | Location is :- '||VAR_2);                   
            END LOOP;           
        CLOSE C_REF;
       
    END;

Comments

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor