In this example, the FOR statement is used to specify a cursor that selects 3 columns from the employee table. For every row selected, SQL variable fullname is set to the last name followed by a comma, the first name, a blank, and the middle initial. Each value for fullname is inserted into table TNAMES.
BEGIN DECLARE fullname CHAR(40); FOR vl AS c1 CURSOR FOR SELECT firstnme, midinit, lastname FROM employee DO SET fullname = lastname || ', ' || firstnme ||' ' || midinit; INSERT INTO TNAMES VALUE ( fullname ); END FOR; END;
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.