background image
<< Using SQL Character Data Types | NCHAR Literal Replacement >>
<< Using SQL Character Data Types | NCHAR Literal Replacement >>

Using Unicode String Literals

Developing Globalized Applications
Working in a Global Environment 6-29
Using the NVARCHAR2 Data Type
The
NVARCHAR2
data type specifies a variable-length character string that uses the
national character set. When you create a table with an
NVARCHAR2
column, you
specify the maximum number of characters for the column. Lengths for
NVARCHAR2
are in units of characters, just as for
NCHAR
. Oracle Database subsequently stores each
value in the column exactly as you specify it, if the value does not exceed the
maximum length of the column. It does not pad the string value to the maximum
length.
The maximum column size allowed is 4000 characters when the national character set
is UTF8, and it is 2000 when AL16UTF16. The maximum length of an
NVARCHAR2
column in bytes is 4000. Both the byte limit and the character limit must be met, so the
maximum number of characters that is allowed in an
NVARCHAR2
column is the
number of characters that can be written in 4000 bytes.
In PL/SQL, the maximum length for an
NVARCHAR2
variable is 32,767 bytes. You can
define
NVARCHAR2
variables up to 32,767 characters, but the actual data cannot exceed
32,767 bytes.
The following statement creates a table with one
NVARCHAR2
column whose
maximum length in characters is 2000 and maximum length in bytes is 4000.
CREATE TABLE table2 (column2 NVARCHAR2(2000));
Using Unicode String Literals
You can input Unicode string literals in SQL and PL/SQL as follows:
Put the letter
N
before a string literal that is enclosed with single quotation marks.
This explicitly indicates that the following string literal is an
NCHAR
string literal.
For example,
N'résumé'
is an
NCHAR
string literal. See
"NCHAR Literal
Replacement"
on page 6-30 for limitations of this method.
Use the
NCHR(
n
)
SQL function. The
NCHR(
n
)
SQL function returns a unit of
character code in the national character set, which is AL16UTF16 or UTF8. The
result of concatenating several
NCHR(
n
)
functions is
NVARCHAR2
data. In this
way, you can bypass the client and server character set conversions and create an
NVARCHAR2
string directly. For example,
NCHR(32)
represents a blank character.
Because
NCHR(
n
)
is associated with the national character set, portability of the
resulting value is limited to applications that use the same national character set. If
this is a concern, then use the
UNISTR
function to remove portability limitations.
Use the
UNISTR
('string'
)
SQL function. The
UNISTR
('string'
)
function
converts a string to the national character set. To ensure portability and to preserve
data, include only ASCII characters and Unicode encoding in the following form:
\xxxx
, where
xxxx
is the hexadecimal value of a character code value in UTF-16
See Also:
Using the NVARCHAR2 Data Type
on page 6-29
Oracle Database Globalization Support Guide for a complete
discussion of programming with Unicode
See Also:
Using the NCHAR Data Type
on page 6-28
Oracle Database Globalization Support Guide for a complete
discussion of programming with Unicode