Oracle ASCIISTR() Function

Oracle ASCIISTR() is a built-in function that returns the ASCII version of a given string in the database character set.

Oracle ASCIISTR() Syntax

Here’s the syntax for the Oracle ASCIISTR() function:

ASCIISTR(str)

Parameters

str

Required. It can be a string or an expression that evaluates to a string in any character set.

Return Value

The Oracle ASCIISTR() function returns the ASCII version of the given string in the database character set. Non-ASCII characters are converted to the format \xxxx, where xxxx represents a UTF-16 code unit.

If any argument is NULL, ASCIISTR() returns NULL.

Oracle ASCIISTR() Examples

Here are some examples that demonstrate how to use the Oracle ASCIISTR() function.

Basic Usage

To return the ASCII string equivalent to the text string ABÄCDE, use the following statement:

SELECT
    ASCIISTR('ABÄCDE')
FROM dual;

输出:

ASCIISTR('ABÄCDE')
_____________________
AB\00C4CDE

In this example, Ä is not an ASCII character and is converted to \00C4.

Here’s another example:

SELECT
    ASCIISTR('你好')
FROM dual;

输出:

ASCIISTR('你好')
_________________
\4F60\597D

NULL Argument

If any argument is NULL, ASCIISTR() returns NULL.

SET NULL 'NULL';
SELECT
    ASCIISTR(NULL)
FROM dual;

输出:

ASCIISTR(NULL)
_________________
NULL

In this example, we use the statement SET NULL 'NULL'; to display NULL values as the string 'NULL'.

Conclusion

Oracle ASCIISTR() is a built-in function that returns the ASCII version of a given string in the database character set.