Iterate, leave, Goto, and return

Source: Internet
Author: User

---- Start

Anyone who has learned any programming language is familiar with continue and break. In SQL PL, iterate and leave play the same role. Return serves the same purpose as most programming languages and is used to return the results to the caller. In addition, the GOTO statement is also supported in SQL pl. It is generally not recommended to use goto because it will confuse the program.

I. Syntax

Iterate label <br/> Leave label <br/> goto label <br/> return <result>

Ii. Example

-- Connect to the database <br/> connect to sample! <Br/> drop procedure test! </P> <p> -- create a stored procedure <br/> Create procedure Test (Out num INT) <br/> begin <br/> declare I int default 1; <br/> set num = 0; </P> <p> L1: While 1 = 1 <br/> DO <br/> set num = num + I; <br/> set I = I + 1; </P> <p> If I <10 then <br/> iterate L1; <br/> end if; </P> <p> If I = 10 then <br/> goto L2; <br/> end if; </P> <p> If I> 10 then <br/> Leave L1; <br/> end if; <br/> end while; </P> <p> L2: Return 0; <br/> end! </P> <p> -- call a stored procedure <br/> call test (?)! </P> <p> -- close the connection <br/> connect reset!

Iii. Call

Save the sample content as C:/test. SQL, and then execute the following command in the DB2 command window <br/> DB2-Td! -Vf c:/test. SQL 


---- For more information, see:SQL pl

----Statement: indicate the source for reprinting.

---- Last updated on 2010.2.4

---- Written by shangbo on 2010.2.1

---- End


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: 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.