Start of change

-312   VARIABLE variable-name IS NOT DEFINED OR NOT USABLE

Explanation

A variable is referenced in the SQL statement, but it either is not defined or cannot be used.

variable-name
The name of the variable that is referenced in the statement.

The following list identifies examples of conditions that result in this SQLCODE:

  • The variable is not declared.
  • The attributes of the variable are inconsistent with its usage in the SQL statement.
  • The host variable was specified in a dynamic SQL statement. Host variables are not valid in dynamic SQL statements.
  • The variable is a host-variable array that was referenced in an unsupported context. Host-variable arrays can be referenced only in certain contexts: in a FETCH statement for a multiple-row fetch, in an INSERT statement for a multiple-row insert, or in a multiple-row MERGE statement.
  • The variable appeared in one of the triggered SQL statements in a CREATE TRIGGER statement. An OLD transition variable cannot be modified in a trigger body.
  • The variable name is used in the body of an SQL procedure, SQL function, or trigger, but the variable is not declared as an SQL variable or parameter. The scope of an SQL variable is the compound statement that contains the declaration, including any compound statements that are nested within that compound statement.
  • The variable appeared in one of the key-expressions of an index definition.
  • A host variable is declared in PL/I with the attributes BINARY, FIXED and UNSIGNED.

System action

The statement cannot be processed.

Programmer response

Do one of the following solutions and try the request again:

  • Verify that the program or SQL routine contains a declaration for the variable. Verify that the variable name in the SQL statement is spelled correctly.
  • Verify that the attributes of the variable are compatible with its use in the statement.
  • Use parameter markers in a dynamic SQL statement instead of host variables.
  • Specify a NEW transition variable when the variable is modified in a trigger.
  • Declare the variable as an SQL variable or parameter in the SQL routine.
  • Check the definition of the index and remove any host variables that are specified.
  • BINARY FIXED UNSIGNED variables cannot be used as host variables in PL/I. Instead, use a BINARY FIXED SIGNED variable with enough precision to represent the range of values needed.

SQLSTATE

42618

End of change