Presentation is loading. Please wait.

Presentation is loading. Please wait.

Definition Cursor is a control structure for the successive traversal of records in a result set. Cursor is a record pointer in a database. DATABASE CURSOR.

Similar presentations


Presentation on theme: "Definition Cursor is a control structure for the successive traversal of records in a result set. Cursor is a record pointer in a database. DATABASE CURSOR."— Presentation transcript:

1

2 Definition Cursor is a control structure for the successive traversal of records in a result set. Cursor is a record pointer in a database. DATABASE CURSOR

3 Use For A cursor is used for processing individual rows returned by the database system for a query. And use for handle a result set

4 Declare Open Fetch Close Free

5 This instruction associates a database cursor with an SQL statement in the current connection.

6 Forward only cursors (non-scrollable ) Scrollable cursors Hold cursors

7 Sequential cursor Forward only cursor can fetch only the next row in sequence from the result set. On each execution of the FETCH statement, the database server returns the contents of the current row and locates the next row in the result set.

8 Syntax Example DECLARE cursor_name CURSOR FOR SELECT... FROM... DECLARE cursor1 CURSOR FOR SELECT * FROM customer_Table

9 Scrollable cursor can fetch rows of the result set in any sequence. You can fetch the first, last, or any intermediate rows of the result set as well as fetch rows repeatedly without having to close and reopen the cursor.

10 Syntax Example DECLARE cursor_name SCROLL CURSOR FOR SELECT... FROM... DECLARE cursor1 SCROLL CURSOR FOR SELECT * FROM customer

11 Ordinarily, all cursors close at the end of a transaction (COMMIT or ROLLBACK). A hold cursor does not close. It remains open after a transaction ends. A hold cursor can be either a sequential cursor or a scrollable cursor.

12 Syntax Example DECLARE cursor_name CURSOR WITH HOLD FOR SELECT... FROM... DECLARE cursor1 CURSOR WITH HOLD FOR SELECT * FROM customer

13 Executes the SQL statement associated with a database cursor declared in the same connection.

14 OPEN cursor_name

15 Moves a cursor to a new row in the corresponding result set and retrieves the row values into fetch buffers.

16 Forward only cursor Scrollable cursor FETCH cursor_name INTO variable [,variable2…] FETCH [ Direction ] cursor_name INTO variable [,variable2…]

17 NEXT -> retrieves the next row in the result set PREVIOUS,PRIOR -> retrieves the previous row in the result set CURRENT -> retrieves the current row in the result set FIRST -> retrieves the first row in the result set. LAST -> retrieves the last row in the result set. ABSOLUTE position -> retrieves the row at position in the result set RELATIVE offset -> moves offset rows in the result set and returns the row at the current position

18 Closes a database cursor and frees resources allocated on the database server for the result set.

19 CLOSE cursor_name

20 This instruction releases resources allocated to the database cursor with the DECLARE instruction.

21 FREE cursor_name

22 CURSOR_NAME%ROWCOUNT -> Return the number of row fetched so far CURSOR_NAME%FOUND -> Return TRUE if the last FETCH returned a row -> Return FALSE if the last FETCH did not return CURSOR_NAME%NOTFOUND -> Return FALSE if the last FETCH returned a row -> Return TRUE if the last FETCH did not return CURSOR_NAME%ISOPEN -> Return TRUE if the cursor is open -> Return FALSE if the cursor is close

23 Cursors can not only be used to fetch data from the DBMS into an application but also to identify a row in a table to be updated or deleted

24 Syntax UPDATE table_name SET... WHERE CURRENT OF cursor_name DELETE table_name SET... WHERE CURRENT OF cursor_name

25 Thank you

26 Puris Chalermpug 5088055 Anawat Boochabuppajarn 5088009 Manthana Atipremanon 5088016 Thunyaluk Kumnurdchati 5088129


Download ppt "Definition Cursor is a control structure for the successive traversal of records in a result set. Cursor is a record pointer in a database. DATABASE CURSOR."

Similar presentations


Ads by Google