Name

TO_CHAR

Synopsis

The TO_CHAR function converts national character set data into its database character set equivalent. The specification of TO_CHAR, at least for this usage, is as follows:

FUNCTION TO_CHAR(char_data IN NVARCHAR2) RETURN VARCHAR2

The TO_CHAR function is defined to accept any of the following types as input: NCHAR, NVARCHAR2, CLOB, and NCLOB. The return type is always VARCHAR2.

Following is an example of TO_CHAR’s being used to translate a string from the national character set into the database character set:

DECLARE 
   a VARCHAR2(30);
   b NVARCHAR2(30) := 'Corner? What corner?';
BEGIN
   a := TO_CHAR(b);
END;

See the discussion of TO_NCHAR under Section 8.5 later in this chapter for information on converting in the other direction. Also see the TRANSLATE...USING function.

Tip

TO_CHAR may also be used to convert date and time values, as well as numbers, into human-readable form. These uses of TO_CHAR are described in Chapter 10 (dates and times) and Chapter 9 (numbers).

Get Oracle PL/SQL Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.