BINARY(binary_string_expression, length)


The BINARY function returns a fixed-length binary string that consists of the binary string expression of length, as specified by the function's second argument. The first argument's data type is either binary or varbinary. The second argument is a numerical integer constant in the range of 1 through 255.

If the first argument is nullable, the result will be nullable and if it is null, the result will be the null value.

The following guidelines apply to the second argument:

  • If you omit the length argument, the product derives the length from the first argument's length. 
  • If the specified length is shorter, the product truncates the string without warning. 
  • If the length is longer, the product pads the result with binary zeros.


Example


UNLOAD SELECT BINARY(BX’123456’,2) FROM SYSIBM.SYSDUMMY1

This results in the fixed binary string of: X’1234’.

UNLOAD SELECT BINARY(BX’123456’,5) FROM SYSIBM.SYSDUMMY1

This results in the fixed binary string of: X’1234560000'.

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*