You are on page 1of 2

What a SELECT FOR UPDATE cursor represent?

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.

What WHERE CURRENT OF clause does in a cursor?


PL/SQL provides the WHERE CURRENT OF clause for both UPDATE and DELETE statements inside a cursor.This allows you to easily make changes to the most recently fetched row of data. Syntax: UPDATE table_name SET set_clause WHERE CURRENT OF cursor_name; Notice that the WHERE CURRENT OF clause references the cursor and not the record into which the next fetched row is deposited.

Can you pass a parameter to a cursor?


PL/SQL also allows you to pass parameters into cursors. It eases your work because: - A parameter makes the cursor more reusable. - A parameter avoids scoping problems. However, you should pass parameters when you are goint to use it at more then one place and when there are hoing to be different values for the same WHERE statement

Explain the functioning of CURSOR FOR LOOP with example.


Lets have a look at what Cursors are before going to the Cursor FOR loop. A Cursor is a PL/SQL construct and accesses the stored information in a named work area. There are 2 types of cursors: Implicit: queries that return only one row Explicit: can be declared by us for the queries that return more than one row.

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;

You might also like