![]() ![]() For example, if the cursor SELECTs a row from the rentals table, there are three possible destinations: The destination (or destination s) must match the shape of a row returned by the cursor. The syntax for the FETCH statement isįETCH cursor-name INTO destination ] When you fetch a row from a cursor, you have to provide one or more destination variables that PL/pgSQL can stuff the results into. FETCHĪfter a bound cursor has been opened, you can retrieve the result set (one row at a time) using the FETCH statement. You can repeat the OPEN, FETCH, CLOSE cycle if you want to process the cursor results again. When you use a cursor, you first DECLARE it, then OPEN it, FETCH from it, and finally CLOSE it, in that order. If you try to FETCH (see the section that follows) from a cursor that has not been opened, you'll receive an error message ( cursor " name " is invalid). If you try to OPEN a cursor that is already open, you will receive an error message ( cursor " name " already in use). ![]() The cursor variable is said to be bound to this query, and the variable is a bound cursor variable.īefore you can use a bound cursor, you must open the cursor using the OPEN statement: When you declare a variable of type CURSOR, you must include a query. Rental_cursor is declared to be a cursor for the result set of the query SELECT * FROM rentals. Rental_cursor CURSOR FOR SELECT * FROM rentals The following code snippet shows how you might declare a cursor variable: You must declare a cursor variable just as you declare any other variable. You can think of a cursor as a name for a result set. Processing a result set using a cursor is similar to processing a result set using a FOR loop, but cursors offer a few distinct advantages that you'll see in a moment. Direct cursor support is new in PL/pgSQL version 7.2. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |