Difference between strong ref cursor and weak ref cursor.

 Difference:

Oracle provides the special type of the datatype for cursor i.e. sys_refcursor which declares the weak ref cursor without declaring it.


Strong ref cursor

 

Weak ref cursor

·        It will always return the value.

         It will not always return the value.

·        Compiler know the structure during the compile time.

         Compiler does not know the structure during the compile time.

·        Dynamic query is not possible.

         Dynamic query is possible.

·        It will always return the know type from usually the declared type object.

         It has return type which is dependent on the SQL statement which executes only once the cursor is opened is the type known at the runtime.

·        Compiler can figure out or determine or find out the problem in the PLSQL block by comparing the types returned to and how they are used.

         Compiler cannot determine the type until it is run. Cursor result set should be cared and handled properly to avoid runtime errors.

·        It is used with select statement that return the result whose data type matches with the one that you have fixed during the STRONG REF cursor declaration.

         It is mostly used with REF cursor which is open for all select statements.

·        Syntax:

 Declare

TYPE ref_cur_name IS REF CURSOR

RETURN return_type;

          Syntax:

Declare

TYPE ref_cur_name is REF CURSOR

 

·        It is also called as the static structure type.

        It is also called as the dynamic structure type.

·        If return type is specified,REF Cursor type and cursor variable are strong.

        If return type is specified, REF Cursor type and cursor variable are strong.

·        Cursor structure is predetermined.

Query cannot be done by using emp%rowtype.

         Cursor structure is not predetermined.

Query can be done by using any structure.

·        It is less error prone.

          It is more error prone.

Strong ref cursor:


 DECLARE
TYPE emprefcur IS REF CURSOR RETURN emp%rowtype;
empc emprefcur;
v_empc empc%rowtype;
BEGIN
open empc for select * from emp;
LOOP
fetch empc into v_empc;
exit when empc%notfound;
DBMS_OUTPUT.PUT_LINE('Employee_Name:-'||v_empc. ename ||', '||'Employee_No:-'||v_empc.empno);
END LOOP;
CLOSE empc;
END;
/





Comments

Popular posts from this blog

Difference between union and union all in oracle sql plsql

Explain oracle pl sql datatypes interview question and answer for fresher and experienced.

Difference between full join and cross join-oracle sql plsql