String Datatypes

Oracle supports four string datatypes, which are summarized in Table 8-1. Which type you should use depends on your answers to the following two questions:

  • Are you working with variable-length or fixed-length strings?

  • Do you wish to use the database character set or the national character set?

Table 8-1. PL/SQL’s string datatypes



Database character set



National character set



You will rarely need or want to use the fixed-length CHAR and NCHAR datatypes in Oracle-based applications; in fact, we recommend that you never use these types unless there is a specific requirement for fixed-length strings. See the upcoming Section 8.3 for a description of problems you may encounter when mixing fixed- and variable-length string variables.

The VARCHAR2 Datatype

VARCHAR2 variables store variable-length character strings. When you declare a variable-length string, you must also specify a maximum length for the string, which can range from 1 to 32767 bytes. You may specify the maximum length in terms of characters or bytes, but either way the length is ultimately defined in bytes. The general format for aVARCHAR2 declaration is:

                  variable_name VARCHAR2 (max_length [CHAR | BYTE]);



Is the name of the variable you wish to declare.


Is the maximum length of the variable.


Indicates that max_length is expressed in terms of characters.


Indicates that max_length represents ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.