Oracle cursor (iii) REF Dynamic Cursor link: Oracle cursor (I) Explicit cursor http://www.bkjia.com/database/201208/150342.html#oraclecursor (ii) Implicit cursor http://www.bkjia.com/database/201208/150344.html REF dynamic cursor is used to process query result sets for multiple rows
In the same PLSQL block, the REF dynamic cursor is different from the specific query binding.
It is bound only when the cursor is opened. Therefore, it is usually used to query the steps for using the dynamic cursor when the statement needs to be dynamically determined during running.
First define a REF Dynamic Cursor type www.2cto.com
Example:
Dynamic cursors are classified into strong and weak types.
Weak type example
Dynamic Cursor example
Generate employee or department information
[SQL] <strong> <span style = "font-size: 18px;"> declare type refcur_t is ref cursor; refcur refcur_t; p_id number; p_name varchar2 (50 ); sel varchar2 (1): = upper (substr ('% tab',); begin if sel = 'E' then open refcur for select id, name from employees; dbms_output.put_line ('employee information'); elsif sel = 'D' then www.2cto.com open refcur for select department_id, department_name from departments; dbms_output.put_line ('department information '); else dbms_output.put_line ('reinput '); return; end if; fetch refcur into p_id, p_name; while refcur % found loop dbms_output.put_line ('#' | p_id | 'P _ name'); fetch refcur into p_id, p_name; end loop; close refcur; end; </span> </strong>