Distributed queries against ASCII or Unicode tables

When you perform a distributed query, the server determines the encoding scheme of the result table.

When a distributed query against an ASCII or Unicode table arrives at the Db2 for z/OS® server, the server indicates in the reply message that the columns of the result table contain ASCII or Unicode data, rather than EBCDIC data. The reply message also includes the CCSIDs of the data to be returned. The CCSID of data from a column is the CCSID that was in effect when the column was defined.

The encoding scheme in which Db2 returns data depends on two factors:

  • The encoding scheme of the requesting system.

    If the requester is ASCII or Unicode, the returned data is ASCII or Unicode. If the requester is EBCDIC, the returned data is EBCDIC, even though it is stored at the server as ASCII or Unicode. However, if the SELECT statement that is used to retrieve the data contains an ORDER BY clause, the data displays in ASCII or Unicode order.

  • Whether the application program overrides the CCSID for the returned data. The ways to do this are as follows:
    • For static SQL

      You can bind a plan or package with the ENCODING bind option to control the CCSIDs for all static data in that plan or package. For example, if you specify ENCODING(UNICODE) when you bind a package at a remote Db2 for z/OS system, the data that is returned in host variables from the remote system is encoded in the default Unicode CCSID for that system.

    • For static or dynamic SQL

      An application program can specify overriding CCSIDs for individual host variables in DECLARE VARIABLE statements.

      An application program that uses an SQLDA can specify an overriding CCSID for the returned data in the SQLDA. When the application program executes a FETCH statement, you receive the data in the CCSID that is specified in the SQLDA.