Professional Documents
Culture Documents
The result of a PREPARE statement is a statement identifier. It is a data structure that represents the prepared statement text. To declare a cursor for the statement text, we associate +- a cursor with the statement identifier. You can associate a sequential cursor with any prepared SELECT or EXECUTE FUNCTION (or EXECUTE PROCEDURE) statement. You cannot associate a scroll cursor with a prepared INSERT statement or with a SELECT statement that was prepared to include a FOR UPDATE clause. The SELECT FOR UPDATE clause in the cursor declaration is a convenient way of modifying the rows that have been retrieved by the cursor.
e.g. DECLARE CURSOR cursor_1 IS SELECT roll_no, student_name FROM student WHERE grade = 4; A PL/SQL program opens a cursor, processes rows returned by a query, then closes the cursor. This can be done with the help of: OPEN, FETCH, and CLOSE statements Cursor FOR Loops Instead of using OPEN, FETCH, and CLOSE statements, coding can be simplified by using FOR loops. A cursor FOR loop opens a cursor, repeatedly fetches rows of values from the result set into fields in the record, then closes the cursor when all rows have been processed. In the example below, the cursor FOR loop implicitly declares stud_record as a record: DECLARE CURSOR cursor_1 IS SELECT student_name, birthdate FROM student; ... BEGIN FOR stud_record IN cuesor_1 LOOP ... ... END LOOP;