DB2 inserts data using Stored Procedures

Source: Internet
Author: User

DB2 needs to insert data using stored procedures: insert three fields (ID, GROUPID [Group id], USERID [user ID]) in a table (TESTMV). To generate multiple groups, the following code is used to calculate the number of persons in each group based on the data of multiple persons in each group:

[Html] delete testmv; create procdedure insertdb () language SQL begin declare v_num int; declare v_num1 int; declare v_num2 varchar (12); set v_num = 0; set v_num1 = 1; loop1: LOOP if (v_num <100) then set v_num = v_num + 1; set v_num1 = 1; loop2: LOOP if (v_num1 <= 100) then insert into testmv (ID, GROUPID, USERID) VALUES ('id' | v_num | v_num1, 'groupid' | v_num, 'userid' | v_num | v_num1 ); set v_num1 = v_num1 + 1; else leave loop2; end if; end loop loop2; else leave loop1; end if; end loop loop1; end; call insertdb (); drop procedure insertdb ();

 

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.