Precautions for using cursors in DB2

Source: Internet
Author: User
Tags cursor in db2

When using a cursor in a DB2 database, you must be cautious when using commit. This article introduces some precautions for using a cursor in DB2 for your reference and hopes to help you.

When using a cursor in DB2, you must use commit with caution. This may be because the session is closed after the commit is completed, causing db2 to report an unopened cursor error, in this case, commands such as commit cannot be included when the cursor is used, which may cause a cursor error.

When using the while LOOP cursor, we must declare an exception so that we can determine whether the cursor has reached the last point, that is, the cursor will not be able to find a new volume after it, which must be processed here, otherwise, the cursor will keep repeating the last message.

The following statement is required:

Declare continue handler for not found
Begin
Set v_notfound = 1;
End;

When the cursor is opened, give v_notfound = 0 and then go through the loop. As long as the cursor does not find a value, it will assign 1 to v_notfound so that the loop can be controlled, and achieve what we want.

DB2 also needs to note that when the type is changed to char, the system will fill him with spaces, which is something we should trim for him.
When a cursor calls a stored procedure, if the called stored procedure has a problem, the system also reports an error that the cursor is not opened.
 

Related Article

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.