Hello guys, getting really close to running my first stored procedure. This one compiles but when I run it with
call test.fttest5('YEAR');
it throws an error
SQL State: 22001 Vendor Code: -303 Message: [SQL0303] Host variable *N not compatible. Cause . . . . . : A FETCH, SELECT, CALL, SET, VALUES INTO, GET DIAGNOSTICS, GET DESCRIPTOR, or SET DESCRIPTOR cannot be performed because the data type of host variable *N is not compatible with the data type of the corresponding list item.
Also how do I specify an unlimited data type in my stored procedure ? I tried DECLARE temp VARCHAR(MAX);
but it did not worked. My platform is ISeries DB2 V5R4.
create procedure test.fttest5
(IN ftExpression CHARACTER(30))
language sql
reads sql data
dynamic result sets 1
begin
declare cmd VARCHAR(50);
declare whr VARCHAR(50)
;
declare x cursor for sl;
set cmd='select * from testSchema.tempTable' ;
if ftExpression IS NOT NULL
THEN
set whr= ftExpression;
END IF;
set cmd=cmd || CASE WHEN whr IS NULL THEN '' ELSE ' ORDER BY ' || whr END;
prepare sl from cmd;
open x;
return;
end
;