DBA > Job Interview Questions > Oracle DBA Interview questions and Answers

Can cursor variables be stored in PL/SQL tables.

More DBA job interview questions and answers at http://dba.fyicenter.com/Interview-Questions/

(Continued from previous question...)

Can cursor variables be stored in PL/SQL tables. If answer is yes, explain how? If not why?

Yes. Create a cursor type - REF CURSOR and declare a cursor variable of that type.
DECLARE
/* Create the cursor type. */
TYPE company_curtype IS REF CURSOR RETURN company%ROWTYPE;

/* Declare a cursor variable of that type. */
company_curvar company_curtype;

/* Declare a record with same structure as cursor variable. */
company_rec company%ROWTYPE;
BEGIN
/* Open the cursor variable, associating with it a SQL statement. */
OPEN company_curvar FOR SELECT * FROM company;

/* Fetch from the cursor variable. */
FETCH company_curvar INTO company_rec;

/* Close the cursor object associated with variable. */
CLOSE company_curvar;
END;

(Continued on next question...)

Other Job Interview Questions