I finally figured out how you can create a stored procedure or run Dynamic compound statements in Netbean’s Database service on the IBMi. My problem was that whenever I tried to run a create stored procedure script the SQL editor didn’t know how to parse it correctly so it would send the command line by line to the database using the semi colon as the delimiter instead of as one contiguous command.
The key to getting this to work in Netbeans is to create a Delimiter that marks the end of the SQL that you want to send to the system. In the example below I send a request that creates 2 temp tables, and then 2 requests to pull the data from those tables. This example is simple and doesnt show the full power of a DCS. The dynamic compound statements allow you to use variables, control logic, cursors, etc… to do database specific tasks. Its like a stored procedure except you don’t have to create it first. see:
It did seem that a dynamic compound statement can’t return a result set for some reason (at least when i tried).
|CREATE TABLE QTEMP.TEST1 AS (SELECT * FROM MYLIB.MYTABLE)|
|CREATE TABLE QTEMP.TEST2 AS (SELECT * FROM MYLIB.MYTABLE)|
|SELECT * FROM QTEMP.TEST2;|
|SELECT * FROM QTEMP.TEST3;|
|CREATE PROCEDURE MYSTOREDPROC (IN MYPARAM VARCHAR(20))|
|DYNAMIC RESULT SETS 1|
|DECLARE c1 CURSOR FOR|
|WHERE FIELD = MYPARAM;|
Below is an example of the error that I was getting when i was running into this issue where the database service was not parsing the CREATE PROCEDURE statement as one contiguous chunk.
Error code -104, SQL state 42601: [SQL0104] Token <END-OF-STATEMENT> was not valid. Valid tokens: ;.
Line 2, column 1
Below is me trying DCS in different IBMi tools