I’ll assume that you’re working on DB2 on an AS400. The answer will be similar, but slightly different in other configurations.
If the stored procedure is written in a compiled language, such as C, PL/1, or RPG, assemble the SQL statement to be executed into a variable, then execute the variable. Here’s a C example:
sprintf(buffer, “CREATE TABLE %s/%s(x INT, y INT)”, libName, tableName);
EXEC SQL EXECUTE IMMEDIATE :buffer;
If you’re coding your stored procedure in SQL, make a separate stored procedure in a compiled language and call it from your original stored procedure.
Sheldon Linker (email@example.com)
Linker Systems, Inc. (www.linkersystems.com)