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.
CURSOR c1 IS
SELECT some_table FROM all_tables;
v_count INTEGER := 1;
FETCH c1 INTO v_some_table;
IF c1%notfound OR v_count > 1000 THEN
v_count := v_count + 1;
-- Does the cursor need to be closed?
IF c1%ISOPEN THEN -- the cursor is open
dbms_output.put_line('Number of rows processed: '||v_count);
Related Code Snippets: