How to use Dynamic Sql Query with OPEN, FETCH and CLOSE statement

 
--====================================================
OPEN FOR, FETCH, and CLOSE Statements
 
The dynamic SQL statement can query a collection if the collection meets the criteria in "Querying a Collection".
See Also:
"OPEN FOR Statement" for syntax details
"FETCH Statement" for syntax details
"CLOSE Statement" for syntax details
--====================================================
 
Example:
 
 
DECLARE
TYPE EMP_CURSOR IS REF CURSOR;
C1 EMP_CURSOR;
 
V_SQL VARCHAR2(200);
 
V_EMP  XX_EMP%ROWTYPE;
 
 
BEGIN
V_SQL := 'SELECT * FROM XX_EMP WHERE DEPTNO = :DEPARTMENT';
 
    OPEN C1 FOR V_SQL USING 10;
 
    LOOP
    FETCH C1 INTO V_EMP;
    EXIT WHEN C1%NOTFOUND;
    dbms_output.put_line ('Employee Name: '||V_EMP.ENAME||' | Salary : '||V_EMP.SAL  );
    END LOOP;
 
    CLOSE C1;
END;
 
   
OUTPUT:-
Employee Name: CLARK | Salary : 2450
Employee Name: KING | Salary : 5000
Employee Name: MILLER | Salary : 1300
x

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