Informix Error -667: Variable variable-name not declared.
Cause and resolution
Variable variable-name not declared.
The specified variable was not declared. Check the spelling of the undeclared variable to ensure that it is not causing the error.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-667 fires when a routine references a variable that was never declared with DEFINE — per the
official guidance, the most common reason is a simple spelling mismatch between the reference and
the declaration.
- A misspelled variable name, per the official guidance — the most common, direct cause.
- A variable referenced outside the scope it was declared in — per the official guidance's pointer to procedural-variable scope rules, a variable local to one block or routine isn't visible in another.
- A
DEFINEstatement accidentally removed or commented out during editing, while references to the variable elsewhere in the routine were left in place.
Solutions / Resolution
- Check the spelling of the undeclared variable, per the official guidance, against its
DEFINEstatement. - Confirm the variable's
DEFINEis in scope at the point it's referenced, since procedural-variable scope is block/routine-based — a variable declared in one routine or block isn't automatically visible in another. - Confirm the
DEFINEstatement itself is actually present, in case it was removed during editing.
Examples
A misspelled reference
CREATE PROCEDURE check_order(p_order_id INT)
DEFINE v_status CHAR(10);
SELECT status INTO v_staus FROM orders WHERE order_id = p_order_id;
-- -667: v_staus was never declared; the actual variable is v_status
END PROCEDURE;
Corrected
CREATE PROCEDURE check_order(p_order_id INT)
DEFINE v_status CHAR(10);
SELECT status INTO v_status FROM orders WHERE order_id = p_order_id;
END PROCEDURE;
Diagnostic Checks
- Compare the reference's exact spelling against its
DEFINEstatement, character by character. - Confirm the
DEFINEis within the same scope as the reference, if spelling checks out.
Related Errors / Related Topics
- -669 — "Variable variable-name redeclared." The mirror-image situation: a variable declared more than once, rather than not declared at all.
Almost always a spelling mismatch or a scope issue — check both against the variable's DEFINE
statement.