Oracle CHR() Function
Oracle CHR()
is a built-in function that returns the character corresponding to the given integer parameter.
Oracle CHR()
returns the character having the binary equivalent to the gaven number as a VARCHAR2
value in either the database character set or, if you specify USING NCHAR_CS
, the national character set.
Oracle CHR()
syntax
Here is the syntax for the Oracle CHR()
function:
CHR(n)
CHR(n USING NCHAR_CS)
Parameters
n
-
Required. A value of
NUMBER
type or any expression that can be implicitly converted to aNUMBER
value. USING NCHAR_CS
-
Optional. It indicates to use national character sets.
Return Value
The Oracle CHR()
function returns the character having the binary equivalent to the gaven number as a VARCHAR2
value in either the database character set or, if you specify USING NCHAR_CS
, the national character set.
For single-byte character sets, if n
is greater than 256, Oracle Database returns the binary equivalent of n mod 256
.
For multibyte character sets, n
must resolve to a full code point. Invalid code points are not validated, and the result of specifying an invalid code point is undefined.
If any parameter is NULL
, CHR()
will return NULL
.
Oracle CHR()
Examples
Here are some examples that demonstrate the usage of the Oracle CHR()
function.
Basic Usage
The following statement uses the Oracle CHR()
function to convert 67
to a character:
SELECT CHR(67)
FROM dual;
Output:
CHR(67)
__________
C
If the parameter n
is greater than 256, the binary equivalent returned by Oracle Database is n mod 256
.
SELECT
CHR(67),
CHR(67 + 256)
FROM dual;
Output:
CHR(67) CHR(67+256)
__________ ______________
C C
USING NCHAR_CS
Oracle CHR()
allows you to use national character sets.
SELECT CHR (257 USING NCHAR_CS)
FROM dual;
Output:
CHR(257USINGNCHAR_CS)
________________________
ā
This is the same as using the NCHR()
function.
NULL Parameters
If any parameter is NULL
, CHR()
will return NULL
.
SET NULL 'NULL';
SELECT
CHR(NULL)
FROM dual;
Output:
CHR(NULL)
____________
NULL
In this example, we use the statement SET NULL 'NULL';
to display NULL
values as the string 'NULL'
.
Conclusion
Oracle CHR()
is a built-in function that returns the character corresponding to the given integer parameter.