BINARY

Click to skip syntax diagram
Read syntax diagramSkip visual syntax diagram>>-BINARY--(--string-expression--+------------+--)-------------><
                                 '-,--integer-'
 

The BINARY function returns a BINARY representation of a string of any type.

The result of the function is a fixed-length binary string. If the first argument can be null, the result can be null; if the first argument is null, the result is the null value.

string-expression
A string-expression whose value must be a built-in character string, graphic string, binary string, or row ID data type.
integer
An integer constant that specifies the length attribute for the resulting binary string. The value must be between 1 and 32766.

If integer is not specified:

The actual length is the same as the length attribute of the result. If the length of the string-expression is less than the length of the result, the result is padded with hexadecimal zeroes up to the length of the result. If the length of the string-expression is greater than the length attribute of the result, truncation is performed. A warning (SQLSTATE 01004) is returned unless the first input argument is a character string and all the truncated characters are blanks, or the first input argument is a graphic string and all the truncated characters are double-byte blanks, or the first input argument is a binary string and all the truncated bytes are hexadecimal zeroes.

Note

Syntax alternatives: When the length is specified, the CAST specification should be used for maximal portability. For more information, see CAST specification.

Example