Informix Error -654: Bad use of PROCEDURE declaration type.
Cause and resolution
Bad use of PROCEDURE declaration type.
The procedure declaration was used either in the parameters or the RETURNING clause. SPL routines cannot accept or return procedures.
An example of the error follows:
CREATE PROCEDURE testproc (proc1 procedure) -- error RETURNING procedure; -- error ... END PROCEDURE
Correction: Do not attempt to use the procedure declaration type within a parameter or the RETURNING clause.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-654 fires when the PROCEDURE declaration type is used in an SPL routine's parameter list or
RETURNING clause — per the official guidance, SPL routines can't accept or return procedures as
values.
- A parameter declared with type
PROCEDURE, per the official guidance — SPL doesn't support passing a procedure as a first-class value. - A
RETURNINGclause specifyingPROCEDURE, per the official guidance — the same restriction on the return side. - An attempt to write a higher-order routine (one that takes or returns another routine), modeled on a pattern from a general-purpose programming language, that SPL doesn't support.
Solutions / Resolution
- Don't use
PROCEDUREas a parameter type orRETURNINGtype, per the official guidance — this isn't supported under any circumstances in SPL. - If dynamic routine invocation is genuinely needed, look up and call the target routine by
name at runtime (via
EXECUTE PROCEDURE/EXECUTE FUNCTIONwith a name resolved dynamically) instead of trying to pass the routine itself as a value.
Examples
The disallowed attempt
CREATE PROCEDURE run_step(p_step PROCEDURE)
EXECUTE PROCEDURE p_step;
END PROCEDURE;
-- -654: PROCEDURE can't be used as a parameter type
An alternative — dynamic invocation by name
CREATE PROCEDURE run_step(p_step_name VARCHAR(128))
DEFINE v_stmt VARCHAR(200);
LET v_stmt = 'EXECUTE PROCEDURE ' || p_step_name || '()';
EXECUTE IMMEDIATE v_stmt;
END PROCEDURE;
Diagnostic Checks
- Scan the routine's parameter list and
RETURNINGclause forPROCEDUREas a declared type, and redesign around passing a routine name (string) instead.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -654 in this set yet.
SPL has no first-class routine values — pass a routine's name as a string and invoke it dynamically instead of trying to pass the routine itself.