Hitachi

Hitachi Advanced Database SQL Reference


8.12.4 CHR

Return the character corresponding to the character code represented by the integer target data.

Organization of this subsection

(1) Specification format

scalar-function-CHR ::= CHR(target-data)
 
  target-data ::= value-expression

(2) Explanation of specification format

target-data:

Specifies the target data.

The value specified in target-data must be a character code corresponding to a single character, expressed as an integer greater than or equal to 0. For example, in the case of the multi-byte character expressed in hexadecimal as 0xE38182, specify 14909826, which is the decimal equivalent of hexadecimal 0xE38182.

The following rules apply:

  • Specify the target data in the form of a value expression. For details about value expressions, see 7.20 Value expression.

  • Specify data of type INTEGER or SMALLINT for the target data.

  • You cannot specify a dynamic parameter by itself for the target data.

The following example illustrates the result of executing the scalar function CHR. The example assumes Unicode (UTF-8) as the character encoding.

Examples:

CHR(65)'A'

CHR(97)'a'

CHR(14845345)'[Figure]'

(3) Rules

  1. The data type of the execution result will be VARCHAR(8).

  2. The NOT NULL constraint does not apply to the value of the execution result (the null value is allowed).

  3. If the target data is the null value or a negative value, the execution result will be a null value.

  4. If the value of the target data exceeds 255, it is treated as a multi-byte character. For example, 14909826, which is the decimal representation of hexadecimal 0xE38182, is treated as a multi-byte character composed of the three bytes 0xE3, 0x81, and 0x82.

(4) Example

Example:

Find the character string data items in column C1 in table T1 that end with the character NL (newline).

SELECT "C1" FROM "T1" WHERE SUBSTR("C1",-1)=CHR(10)

[Figure]