Character-string constants

A character-string constant specifies a varying-length character string.

The two forms of character-string constant follow:

  • A sequence of characters that starts and ends with a string delimiter. The number of bytes between the string delimiters cannot be greater than 32740. Two consecutive string delimiters are used to represent one string delimiter within the character string. Two consecutive string delimiters that are not contained within a string represent the empty string.
  • An X followed by a sequence of characters that starts and ends with a string delimiter. The characters between the string delimiters must be an even number of hexadecimal digits. Blanks between the string delimiters are ignored. The number of hexadecimal digits must not exceed 32762. A hexadecimal digit is a digit or any of the letters A through F (uppercase or lowercase). Under the conventions of hexadecimal notation, each pair of hexadecimal digits represents a character. This form of string constant allows you to specify characters that do not have a keyboard representation.

Character-string constants can contain mixed data. If the job CCSID supports mixed data, a character-string constant is classified as mixed data if it includes a DBCS substring. In all other cases, a character-string constant is classified as SBCS data.

The CCSID assigned to the constant is the CCSID of the SQL statement text containing the constant unless the SQL statement is encoded in Unicode or a foreign encoding scheme (such as ASCII). In this case, the SQL statement text is converted from Unicode or the foreign encoding scheme to the default CCSID of the current server. The CCSID assigned to the constant will be the default CCSID of the current server1.

The CCSID of the SQL statement text is defined in the following table.

Table 1. CCSID of the SQL statement text for different interfaces
SQL Interface CCSID of SQL statement text
Embedded SQL
  • For static statements, the CCSID of the source file for the CRTSQLxxx command.
  • For dynamic statements, the CCSID of the variable specified on the PREPARE statement, or if a string constant is specified on the PREPARE statement, the CCSID of the source file for the CRTSQLxxx command.
RUNSQLSTM The CCSID of the specified source file.
STRSQL and RUNSQL The default CCSID of the current server.
Call Level Interface (CLI) on the server

Unicode, if SQL_ATTR_UCS2, SQL_ATTR_UTF8, or wide APIs are specified.

Otherwise, the default CCSID of the current server. The SQL_ATTR_NON_HEXCCSID environment variable can be used to specify the DFTCCSID job attribute instead.

ODBC on a client using the IBM® i Access Family ODBC Driver

Unicode, if UNICODESQL is specified.

Otherwise, the default CCSID of the current server. If the default CCSID is 65535, the CCSID used will be the value of the DFTCCSID job attribute.

JDBC or SQLJ on the server using IBM Developer Kit for Java™ Unicode
JDBC on a client using the IBM Toolbox for Java Unicode
OLE DB on a client using the IBM i Access Family OLE DB Provider Unicode
.ADO .NET on a client using the IBM i Access Family ODO .NET Provider Unicode

Character-string constants are used to represent constant datetime values in assignments and comparisons. For more information see String representations of datetime values.

Examples

   'Peggy'     '14.12.1990'     '32'     'DON''T CHANGE'     ''     X'FFFF'
1 If the default CCSID is 65535, the CCSID used will be the value of the DFTCCSID job attribute.