Skip Headers

Oracle9i SQL Reference
Release 2 (9.2)

Part Number A96540-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page Go to next page
View PDF

CHR

Syntax

chr::=

Text description of functions42.gif follows
Text description of chr


Purpose

CHR returns the character having the binary equivalent to n in either the database character set or the national character set.

If USING NCHAR_CS is not specified, then this function returns the character having the binary equivalent to n as a VARCHAR2 value in the database character set.

If USING NCHAR_CS is specified, then this function returns the character having the binary equivalent to n as a NVARCHAR2 value in the national character set.

For single-byte character sets, if n > 256, then Oracle returns the binary equivalent of n mod 256. For multibyte character sets, n must resolve to one entire codepoint. Invalid codepoints are not validated, and the result of specifying invalid codepoints is indeterminate.


Note:

Use of the CHR function (either with or without the optional USING NCHAR_CS clause) results in code that is not portable between ASCII- and EBCDIC-based machine architectures.


See Also:

NCHR

Examples

The following example is run on an ASCII-based machine with the database character set defined as WE8ISO8859P1:

SELECT CHR(67)||CHR(65)||CHR(84) "Dog" FROM DUAL;

Dog
---
CAT

To produce the same results on an EBCDIC-based machine with the WE8EBCDIC1047 character set, the preceding example would have to be modified as follows:

SELECT CHR(195)||CHR(193)||CHR(227) "Dog" 
   FROM DUAL; 

Dog 
--- 
CAT 

For multibyte character sets, this sort of concatenation gives different results. For example, given a multibyte character whose hexadecimal value is a1a2 (a1 representing the first byte and a2 the second byte), you must specify for n the decimal equivalent of 'a1a2', or 41378. That is, you must specify:

SELECT CHR(41378) FROM DUAL;

You cannot specify the decimal equivalent of a1 concatenated with the decimal equivalent of a2, as in the following example:

SELECT CHR(161)||CHR(162) FROM DUAL;

However, you can concatenate whole multibyte codepoints, as in the following example, which concatenates the multibyte characters whose hexadecimal values are a1a2 and a1a3:

SELECT CHR(41378)||CHR(41379) FROM DUAL;

The following example uses the UTF8 character set:

SELECT CHR (50052 USING NCHAR_CS) FROM DUAL; 

CH 
-- 
Ä