Definition:
In Oracle PL/SQL, a cursor provides a way to assign a name to a SELECT statement, and then manipulate the information within that SQL statement.
A cursor can be thought of as a pointer used to fetch rows from a result set. You can also visualize a cursor as a data structure that describes the results returned from a SELECT statement. One of the variables in this structure is a pointer to the next record to be fetched from the results of the query.
Example Usage:
DECLARE
CURSOR c1 IS
SELECT some_table FROM all_tables;
v_some_table all_tables.some_table%TYPE;
v_count INTEGER := 1;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO v_some_table;
IF c1%notfound OR v_count > 1000 THEN
EXIT;
END IF;
v_count := v_count + 1;
END LOOP;
-- Does the cursor need to be closed?
IF c1%ISOPEN THEN -- the cursor is open
CLOSE c1;
END IF;
dbms_output.put_line('Number of rows processed: '||v_count);
END;
/
Related Links:
Related Code Snippets: