Use of dynamic cursors In the DB2 database (1)

Source: Internet
Author: User

This article describes how to use dynamic cursors in a DB2 database. If you are interested in using dynamic cursors in a DB2 stored procedure, the following is a detailed description of the main content of the article.

Create procedure data_wtptest (IN in_taskid_timestamp varchar (30 ),
OUT o_err_no int, OUT o_err_msg varchar (1024 ))
Language SQL P1: BEGIN ATOMIC
Declaration start
Temporary Variable Error variable
Declare sqlcode integer default 0;
DECLARE SQLStmt varchar (1024) default '';
DECLARE r_code integer default 0;
DECLARE state varchar (1024) default 'aaa ';
 
Record the current work of the program
DECLARE at_end int DEFAULT 0;
DECLARE t_destnetid int default 0;
DECLARE t_recvid varchar (30) default '';
DECLARE SP_Name varchar (50) default 'data _ integrate ';
Declare the cursor value in the DB2 Stored Procedure

Declare Dynamic Cursor storage variables
DECLARE stmt1 STATEMENT;
DECLARE c1 cursor for stmt1;
Declarative error handling

Declare exit handler for sqlexception begin set r_code = SQLCODE;
Set o_err_no = 1;
Set o_err_msg = 'process [' | state | '] error,' | 'error code SQLCODE: [' | CHAR (r_code) | '].';
Insert into fcc_sp_log (object, name, value) values (SP_Name, in_taskid_timestamp, o_err_msg );
End;
DECLARE continue HANDLER for not found begin set at_end = 1;
Set state = 'found 0 rows of records or has reached the end of the record .';


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.