Strings

A string is a sequence of characters up to 2 GB in size. A string can occur in SQL:

  • as a string literal. A string literal is a sequence of characters enclosed in single quotes (apostrophes). A string literal represents a particular, constant value, and it may contain escape sequences for special characters that cannot be easily typed as characters. See String literals.
  • as the value of a column or variable with a CHAR or NCHAR data type.
  • as the result of evaluating an expression.

The length of a string can be measured in two ways:

  • Byte length   The byte length is the number of bytes in the string.

  • Character length   The character length is the number of characters in the string, and is based on the character set being used.

For single-byte character sets, such as cp1252, the byte-length and character-length are the same. For multibyte character sets, a string's byte-length is greater than or equal to its character-length.