Question

I'm new to IBM DB2, using the iSeries Navigator, IBM iSeries Access for Windows Version 5 Release 4, the "Run SQL Scripts" utility.

Is it possible to use a variable in this utility? A number of Stack Overflow answers (and answers on other forums) instruct one to use code like the following:

BEGIN ATOMIC
DECLARE x VARCHAR(1);
SET x = 'A';
SELECT * FROM  MySchema.MyTable Where MyColumn = x;
END@

This does not work inside the "Run SQL Scripts" utility, throwing the exception "Token ATOMIC was not valid." If I remove the keyword ATOMIC I get the error "Token X was not valid." If I remove the entire BEGIN and END lines I get the error "Token VARCHAR was not valid."

Another set of answers instruct one to use code like the following, which also fails with the same "...not valid" errors:

CREATE VARIABLE x VARCHAR(1) DEFAULT ('A');
SELECT * FROM MySchema.MyTable WHERE MyColumn = x;
DROP VARIABLE x;

Is it possible to declare variables in the "Run Sql Scripts" utility?

Was it helpful?

Solution

Global variable support and dynamic compound statement support were added to DB2 for i at 7.1.

Is the system itself still running v5r4? Or are you just running a back level version of Client Access? If the later, upgrade your IBM iAccess to 7.1. If the former, you're SOL until the system gets upgraded.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top