Derivation of code page values

The application code page is derived from the active environment when the database connection is made.

If the DB2CODEPAGE registry variable is set, its value is taken as the application code page. However, it is not necessary to set the DB2CODEPAGE registry variable because Db2® determines the appropriate code page value from the operating system. Setting the DB2CODEPAGE registry variable to incorrect values can cause unpredictable results.

When you create a database, you can explicitly specify the database code page. If you do not specify the database code page, the database uses Unicode by default.

How the active environment is determined in different operating environments:

Linux® and UNIX operating systems
On Linux and UNIX operating systems, the active environment is determined from the locale setting, which includes information about language, territory and code set.
Windows operating systems
For all Windows operating systems, if the DB2CODEPAGE environment variable is not set, the code page is derived from the ANSI code page setting in the Regional Options menu in the Control Panel.

Normally, Windows does not report a Unicode code page in place of the aforementioned ANSI code page. Therefore, a Windows application typically does not behave as a Unicode client. To override this behavior, the DB2CODEPAGE variable can be set to a Unicode code page (1208), which forces the application to behave as a Unicode client.

Note:
Windows does not have a locale setting that reports GB18030 as the code set. Starting in Db2 V9.7 Fix Pack 1, to ensure that a Db2 client treats a Windows workstation as using GB18030 code set (code page 1392), complete the following tasks:
  • Install the GB18030 Support Package, which is available from Microsoft.
  • In the Regional and Language Options, set the Language for non-Unicode programs setting to Chinese PRC.
  • Set the DB2CODEPAGE registry variable to 1392.

The section code page is derived from the tables used in an SQL statement. If the tables are implicitly or explicitly defined with CCSID ASCII, then the section code page is the same as the database code page. If the tables are defined with CCSID UNICODE, then the section code page is the Unicode code page.

Active code page for precompilation and binding

At precompile/bind time, the precompiler is the executing application. The active code page when the database connection was made before the precompile request is used for precompiled statements, and any character data returned in the SQLCA.

Active code page for application execution

At execution time, the active code page of the user application when a database connection is made is in effect for the duration of the connection. All data is interpreted based on this code page; this includes dynamic SQL statements, user input data, user output data, and character fields in the SQLCA.