IBM Support

SQL0302N when inserting non-ASCII characters.

Troubleshooting


Problem

Receive an SQL0302N error when inserting non-ASCII character data into tables if the database is defined with code set UTF-8.

Symptom


When working with character string data in UTF-8, you should not assume that each character is one byte. In multibyte UTF-8 encoding, each ASCII character is one byte, but non-ASCII characters take two to four bytes each. This should be taken into account when defining CHAR/VARCHAR fields if you plan to use any non-ASCII characters.

See the Related URL section for a link to the IBM Information Center which has a complete description of the error message.

Resolving The Problem

Depending on the ratio of ASCII to non-ASCII characters, a CHAR field of size n bytes can contain anywhere from n/4 to n characters.

Check the database configuration to find the database code page.

db2 "GET DB CFG FOR sample"

Here is the sample output:

Database code page = 1208
Database code set = UTF-8
Database country/region code = 1

Increase the length of the column for the char/Varchar column for existing table based on your requirement. Here is a sample command.

db2 "ALTER TABLE Employee ALTER COLUMN EmplNum SET DATA TYPE VARCHAHR(256)"

Related Information

[{"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Database Objects\/Config - Tables","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"9.7;9.5;9.1;10.1","Edition":"Enterprise Server;Workgroup Server","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
23 June 2018

UID

swg21410823