Binary strings

A binary string is a sequence of bytes. Unlike a character string which usually contains text data, a binary string is used to hold non-traditional data such as pictures. The length of a binary string is the number of bytes in the sequence. A binary string has a CCSID of 65535. Only character strings of FOR BIT DATA are compatible with binary strings.

Fixed-length binary strings

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

Varying-length binary strings

The types of varying-length binary strings are:

  • VARBINARY
  • BLOB

A Binary Large OBject (BLOB) column is useful for storing large amounts of noncharacter data, such as pictures, voice, and mixed media. Another use is to hold structured data for exploitation by distinct types and user-defined functions.

Distinct types, columns, and variables all have length attributes. When varying-length binary-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 binary string, the length attribute must be between 1 through 32 740 bytes inclusive. For a BLOB string, the length attribute must be between 1 through 2 147 483 647 inclusive. See SQL limits for more information.

Binary-string variables

A variable with a binary string type can be defined in all host languages except REXX, RPG/400®, and COBOL/400.

  • BINARY fixed-length binary-string variables can be defined in all host languages except REXX, RPG/400, and COBOL/400.
    • In ILE RPG, a BINARY fixed-length binary-string variable is declared using the SQLTYPE keyword.
    • In all other languages, an SQL TYPE IS BINARY clause is used.
  • VARBINARY varying-length binary-string variables can be defined in all host languages except REXX, RPG/400, and COBOL/400.
    • In ILE RPG, a VARBINARY varying-length binary-string variable is declared using the SQLTYPE keyword.
    • In all other languages, an SQL TYPE IS VARBINARY clause is used.
  • BLOB varying-length binary-string variables can be defined in all host languages except REXX, RPG/400, and COBOL/400.
    • In ILE RPG, a BLOB varying-length binary-string variable is declared using the SQLTYPE keyword.
    • In all other languages, an SQL TYPE IS BLOB clause is used.