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