- Categories:
TO_BINARY¶
Converts the input expression to a binary value. For NULL input, the output is NULL.
See also:
Syntax¶
Returns¶
The return type is BINARY.
Arguments¶
Required:
string_exprA string expression.
Optional:
formatThe binary format for conversion: HEX, BASE64, or UTF-8 (see Binary input and output). The default is the value of the BINARY_INPUT_FORMAT session parameter. If this parameter is not set, the default is HEX.
Returns¶
Returns a value of type BINARY.
Examples¶
These examples show the output when TO_BINARY is called.
This example shows how to convert a VARCHAR to BINARY and then get it
back in its original form (VARCHAR).
Create and fill a table:
Convert the
VARCHARtoBINARY:Run a query and show the output:
This example shows how to convert a string of UTF-8 characters into
BINARY. Note that by default SNOWSQL shows BINARY values as a string
of hexadecimal digits, not in UTF-8 and not in the internal BINARY format.
This example is the same as the preceding example, except that this example explicitly converts the output to hexadecimal digits so that it is more obvious that the output is a string containing hexadecimal digits: