VARCHAR2
VARCHAR2 is the workhorse string type in the Oracle database. VARCHAR2
is a variable length string that must have it’s maximum length declared
before use. In Oracle 10g, a VARCHAR2 column may be up to 4000 bytes
and it may be up to 32767 bytes in a PL/SQL program.
VARCHAR2 can store any type of non-binary data. Depending on the
language defined in the database (either double or multibyte), the
actual number of characters may be less than the number of bytes. For
example, if the language requires three bytes per character, the most
you can store would be 32767 divided by 3 characters.
You may declare a NVARCHAR2 instead of VARCHAR2. NVARCHAR2 is used
for storing unicode character sets. I personally have never had a use
for NVARCHAR2. If you write multi-lingual applications and use a
unicode character set, use NVARCHAR2 instead of VARCHAR2. Length
restrictions are the same as a VARCHAR2 and UTF8 can store 32767
divided by 2 and UTF16 can store 32767 divided by 3. You cannot mix and
match VARCHAR2 and NVARCHAR2 variables. You should pick one or the
other and stick with it. Both are available in SQL and PL/SQL.
To declare a VARCHAR2, you can specify either the number of bytes
or the number of characters. Specify the number of characters if you
use a multi-byte character set. Otherwise, specify bytes.
A declaration looks like this: VARCHAR2(30) That would declare a 30
byte string and is equivalent to VARCHAR2(30 BYTE). To declare a 30
character string, use: VARCHAR2(30 CHAR). In the character set I use,
VARCHAR2(30), VARCHAR2(30 BYTE) and VARCHAR2(30 CHAR) will store
exactly the same number of characters.