-331   CHARACTER CONVERSION CANNOT BE PERFORMED BECAUSE A STRING, POSITION position-number, CANNOT BE CONVERTED FROM source-ccsid TO target-ccsid, REASON reason-code

Explanation

The operation required the conversion from source-ccsid to target-ccsid and a conversion error occurred. The type of error is indicated by the reason-code:
  • 8 for length exception (for example, expansion required for PC MIXED data exceeds the maximum length of the string).
  • 12 for invalid code-point (for example, use of the ERRORBYTE option of SYSSTRINGS).
  • 16 for form exception (for example, invalid MIXED data).
  • 20 for conversion procedure error (for example, an exit set the length control field of the string to an invalid value). You can find the procedure name in SYSIBM.SYSSTRINGS row with INCCSID=source-ccsid and OUTCCSID=target-ccsid in the TRANSPROC column.

The position-number, if provided (non-zero), is the ordinality of the output variable in the SQLDA.

System action

The statement cannot be processed.

Programmer response

Take one of the following actions based on the reason-code:
8
Extend the maximum length of the result column to allow for the expansion that occurs when the string is converted.
12
Change the conversion table to accept the code-point, or change the data to eliminate the code-point.
16
If the string is described as MIXED data, change its description or change the string to conform to the rules for well-formed MIXED data.
20
Correct the conversion procedure.
An alternative to these corrective actions is to provide an indicator variable so that a null value and a warning can be returned rather than an error.

SQLSTATE

22021