=================================
Currently, cursor variables are subject to the following restrictions:
Cannot declare cursor variables in a package spec.
Expand|Select|Wrap|Line Numbers
- CREATE PACKAGE emp_stuff AS
- TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
- emp_cv EmpCurTyp; -- not allowed
- END emp_stuff;
If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless you also open it there on the same server call.
Cannot use comparison operators to test cursor variables for equality,inequality, or nullity.
Cannot assign nulls to a cursor variable.
Database columns cannot store the values of cursor variables. There is no equivalent type to use in a CREATE TABLE statement.
Cannot store cursor variables in an associative array, nested table, or varray.
Cursors and cursor variables are not interoperable; that is,cannot use one where the other is expected. For example, you cannot reference a cursor variable in a cursor FOR loop.
Sample Program---- Fetching from a Cursor Variable into Collections
==================================================
Expand|Select|Wrap|Line Numbers
- DECLARE
- TYPE EmpCurTyp IS REF CURSOR;
- TYPE NameList IS TABLE OF emp.ename%TYPE;
- TYPE SalList IS TABLE OF emp.sal%TYPE;
- emp_cv EmpCurTyp;
- names NameList;
- sals SalList;
- BEGIN
- OPEN emp_cv FOR SELECT ename,sal FROM emp WHERE sal < 3000;
- FETCH emp_cv BULK COLLECT INTO names, sals;
- CLOSE emp_cv;
- FOR i IN names.FIRST .. names.LAST
- LOOP
- dbms_output.put_line('Name = ' || names(i) || ', salary = ' ||
- sals(i));
- END LOOP;
- END;
============================
1.Cannot use a cursor expression with an implicit cursor.
2.Cursor expressions can appear only:
In a SELECT statement that is not nested in any other query expression, except
a.When it is a subquery of the cursor expression itself.
b.As arguments to table functions, in the FROM clause of a SELECT statement.
3.Cursor expressions can appear only in the outermost SELECT list of the query specification.
4.Cursor expressions cannot appear in view declarations.
5.Cannot perform BIND and EXECUTE operations on cursor expressions.
Sample Example of Cursor Expressions
==============================
Expand|Select|Wrap|Line Numbers
- DECLARE
- TYPE emp_cur_typ IS REF CURSOR;
- emp_cur emp_cur_typ;
- dept_name dept.dname%TYPE;
- emp_name emp.ename%TYPE;
- CURSOR c1 IS SELECT
- dname, CURSOR
- (
- SELECT e.ename FROM emp e
- WHERE e.deptno = d.deptno
- ) employees
- FROM dept d
- WHERE dname like '%A%';
- BEGIN
- OPEN c1;
- LOOP
- --fetch the cursor into target variables.
- FETCH c1 INTO dept_name, emp_cur;
- EXIT WHEN c1%NOTFOUND;
- dbms_output.put_line('Department: ' || dept_name);
- LOOP
- FETCH emp_cur INTO emp_name;
- --exit when there is no more data in the cursor.
- EXIT WHEN emp_cur%NOTFOUND;
- dbms_output.put_line(' Employee: ' || emp_name);
- END LOOP;
- END LOOP;
- CLOSE c1;
- END;