Using a SELECT ... INTO Statement
As indicated in the diagram for FOREACH, not all clauses and
options of the SELECT statement are available for you to use in a
FOREACH statement. The SELECT statement in the FOREACH statement must
include the INTO clause. It can also include UNION and ORDER BY clauses,
but it cannot use the INTO TEMP clause. For a complete description
of SELECT syntax and usage, see SELECT statement. The data type and count
of each variable in the variable list must match each value that the SELECT
... INTO
statement returns.
The
database server issues an error if you include a semicolon (
;
)
within the FOREACH statement to terminate the SELECT ... INTO
specification.
The following program fragment, for example, fails with a syntax error:CREATE DBA PROCEDURE IF NOT EXISTS shapes() DEFINE vertexes SET( point NOT NULL ); DEFINE pnt point; SELECT definition INTO vertexes FROM polygons WHERE id = 207; FOREACH cursor1 FOR SELECT * INTO pnt FROM TABLE(vertexes); -- Semicolon not valid . . . END FOREACH . . . END PROCEDURE;In the example above, you can avoid this error by deleting the semicolon that immediately follows the
TABLE(vertexes)
specification.