Hi Thomas,
Finally someone who likes efficient SQL :-)
SELECT INTO is an equivalent to SET. However SELECT INTO is not enabled in the dynamic
compound.
The direct translation of what you presented:
BEGIN ATOMIC
DECLARE x INT;
SET x = (select count(*) into x from employee);
SET x = x+30000;
update employee set salary=x;
END
%
Or
BEGIN ATOMIC
DECLARE x INT;
SET x = (select count(*) into x from employee) + 30000;
update employee set salary=x;
END
%
Or in pure SQL.
UPDATE employee set salary=(select count(*) into x from employee) + 30000;
Note that the original (silly) FOR loop does NOT open a cursor in a dynamic compound
statement.
The technology used is "inline" SQL PL. What you write is one big honking "query". Variable
references are correlations (no bindin, bindout, context switches, etc...)
Cheers
Serge
--
Serge Rielau
DB2 UDB SQL Compiler Development
IBM Software Lab, Canada