Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why REF CURSOR variable is reused to declare REF CURSOR variable ?

bootstrapDec 18 2010 — edited Dec 18 2010
Hi,
Actually i am confused how to write my problem in the above subject part. So, perhaps subject may seems to be confusing or it may be not clear. Ok let me give an example to explain my problem.Here is the code:
DECLARE
TYPE MY_CUR IS REF CURSOR;
CURSOR C IS SELECT * FROM T_GKM_TEST;
MY_ROW T_GKM_TEST%ROWTYPE;
L_CUR MY_CUR;
BEGIN
OPEN L_CUR FOR 'SELECT * FROM T_GKM_TEST';
LOOP 
FETCH L_CUR INTO MY_ROW;
EXIT WHEN L_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(MY_ROW.EMP_ID);
END LOOP;
OPEN L_CUR FOR 'SELECT * FROM T_GKM_TEST';
LOOP 
FETCH L_CUR INTO MY_ROW;
EXIT WHEN L_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(MY_ROW.EMP_NAME);
END LOOP;
END;
In the above code, 'MY_CUR' is a REF CURSOR type variiable. This is like a pointer that can point to any query.
But why i have to reuse 'MY_CUR' in this statement : ' L_CUR MY_CUR; '
Why i have to create another variable ' L_CUR ' which is of type ' MY_CUR ' ?
Why can't i directly use ' MY_CUR ' to refer any sql statement like this :
OPEN MY_CUR FOR 'SELECT * FROM T_GKM_TEST';
The above statement is giving error :
PLS-00330: invalid use of type name or subtype name
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2011
Added on Dec 18 2010
2 comments
619 views