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

Q

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

✍: Guest

A

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;

2011-10-25, 2719👍, 0💬