Precautions for using DB2 cursors

Source: Internet
Author: User

1. Procedure for using a cursor

(1) define a cursor

Exec SQL DECLARE MY_CURSOR CURSOR ........

(2) Open the cursor

Exec SQL OPEN MY_CURSOR;

(3) read cursor

Exec SQL FETCH MY_CURSOR INTO: MY_Stru;

(4) Close the cursor

Exec SQL CLOSE MY_CURSOR;

2. Notes

(1) The SQLCODE judgment should be added to each step.

(2) If a COMMIT or roll back operation exists after the cursor is read, The with hold option must be added when the cursor is defined to ensure that the cursor is not closed after submission.

(3) After the cursor is read, a logical operation is generally performed. If an error is returned and the operation exits, the cursor must be closed.

(4) for read-ONLY operations, add for read only when defining the cursor

(5) for update operations, add for update when defining the cursor. You can also specify the updated field.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.