When I run the stored procedure in the Data Studio debugger, the value of the variable representing the concatenated string is 256 characters long. I increased the variable display length in the debugger with no change in theoutput.
string:
SET n_sql='INSERT INTO SESSION.TABLE_TEMP '||
'SELECT * FROM TABLE1 W '||
'WHERE W.status = VARCHAR(9) and W.ADDDATE < CURRENT_TIMESTAMP - '||db_days||' DAYS '||
'AND NOT EXISTS (select 1 from '||schema_name|| '.TABLEDETAILS T where T.TableKey = W.TableKey) ORDER BY TableKey FETCH FIRST 100 ROWS ONLY;';
debugger output for n_sql:
INSERT INTO SESSION.TABLE_TEMP SELECT * FROM TABLE1 W WHERE W.status = VARCHAR(9) and W.ADDDATE < CURRENT_TIMESTAMP - 10 DAYS AND NOT EXISTS (select 1 from schema1.TABLEDETAILS T where T.TableKey = W.TabletKey) ORDER BY TableKey FETCH FIRST 10
error message:
A database manager error occurred.SQLCODE: -104, SQLSTATE: 42601 - An unexpected token "" was found following "". Expected tokens may include: "FIRST 100 ROWS ONLY".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.11.69