basic PL/SQL questions
Date: Tue, 6 Jan 2004 10:05:57 -0500
Message-ID: <2sadnQlIf8R-U2eiRVn-uQ_at_magma.ca>
Please excuse the basic nature of these questions - I'm just starting off.
This example is taken from Oracle PL/SQL 101 - Osborne/McGraw-Hill - ISBN 0-07-212606-X - page 314
- DECLARE
- CURSOR product_cur IS
- SELECT * FROM plsql101_product
- FOR UPDATE OF product_price;
- BEGIN
- FOR product_rec IN product_cur
- LOOP
- UPDATE plsql101_product
- SET product_price = (product_rec.product_price = 0.97)
- WHERE CURRENT OF product_cur
- END LOOP;
- END;
The way a cursor works is that once a record is fetched it is taken out of the cursor. This works well until the last record is reached at which time fetch will continue to return the last record in the cursor unless you use the %FOUND and %NOTFOUND constructs to test for the last record?
The cursor loop used in the above example eliminates the need to open, close and fetch. It also eliminates the need to check for the last record.
There is no formal declaration of the cursor name "product_rec" first used on line 6. Is this an example of an implicit cursor of table-based record type?
On line 9 how does PL/SQL know that there is a product_price field in the cursor record? Is this also part of the implicit cursor definition?
Thanks
J. Received on Tue Jan 06 2004 - 16:05:57 CET