Creating compound statements
Creating and executing compound statements is a task that you would perform when you need to run a script consisting of SQL statements.
Before you begin
- Read: Compound statements
- Ensure that you have the privileges required to execute the Compound statement.
Procedure
- Define a compound SQL statement.
- Execute the compound SQL statement from a supported interface.
Results
Example
BEGIN
FOR row AS
SELECT pk, c1, discretize(c1) AS v FROM source
DO
IF row.v is NULL THEN
INSERT INTO except VALUES(row.pk, row.c1);
ELSE
INSERT INTO target VALUES(row.pk, row.d);
END IF;
END FOR;
ENDThe compound statement is bounded by the keywords
BEGIN and END. It includes use of both the FOR and IF/ELSE control-statements
that are part of SQL PL. The FOR statement is used to iterate through
a defined set of rows. For each row a column's value is checked and
conditionally, based on the value, a set of values is inserted into
another table.