Character strings

A character string is a sequence of bytes. The length of the string is the number of bytes in the sequence. If the length is zero, the value is called the empty string. The empty string should not be confused with the null value.

Fixed-length character strings

When fixed-length character string distinct types, columns, and variables are defined, the length attribute is specified and all values have the same length. For a fixed-length character string, the length attribute must be between 1 through 32766 inclusive. See SQL limits for more information.

Varying-length character strings

The types of varying-length character strings are:

  • VARCHAR
  • CLOB

A Character Large OBject (CLOB) column is useful for storing large amounts of character data, such as documents written using a single character set.

Distinct types, columns, and variables all have length attributes. When varying-length character-string distinct types, columns, and variables are defined, the maximum length is specified and this becomes the length attribute. Actual values may have a smaller length. For a varying-length character string, the length attribute must be between 1 through 32 740 inclusive. For a CLOB string, the length attribute must be between 1 through 2 147 483 647 inclusive. See SQL limits for more information.

For the restrictions that apply to the use of long varying-length strings, see Limitations on use of strings.

Character-string variables

  • Fixed-length character-string variables can be used in all host languages except REXX and Java™. (In C or C++, fixed-length character-string variables are limited to a length of 1.)
  • VARCHAR varying-length character-string variables can be used in C, C++, COBOL, PL/I, REXX, and RPG:
    • In PL/I, REXX, and ILE RPG, there is a varying-length character-string data type.
    • In COBOL, C, and C++ varying-length character strings are represented as structures.
    • In C and C++, varying-length character-string variables can also be represented by NUL-terminated strings.
    • In RPG/400®, varying-length character-string variables can only be represented by VARCHAR columns included as a result of an externally described data structure.
  • CLOB varying-length character-string variables can be defined in all host languages except REXX, RPG/400, and COBOL/400.
    • In ILE RPG, a CLOB varying-length character string is declared using the SQLTYPE keyword.
    • In all other languages, an SQL TYPE IS CLOB clause is used.