content_image/829080.jpg
+------+---------+------------------------+ 

The preceding examples use HEX()  to display the WEIGHT_STRING()  result. Because the result is a binary value, HEX()  can be especially useful when the result contains nonprinting values, to display it in printable form: 

mysql> SET @s = CONVERT(X’C39F’ USING utf8) COLLATE utf8_czech_ci; mysql> SELECT HEX(WEIGHT_STRING(@s)); +------------------------+ | HEX(WEIGHT_STRING(@s)) | +------------------------+ | 0FEA0FEA | +------------------------+ 

For non- NULL  return values, the data type of the value is VARBINARY  if its length is within the maximum length for VARBINARY , otherwise the data type is BLOB . 

The AS  clause may be given to cast the input string to a nonbinary or binary string and to force it to a given length: 

• AS CHAR( N )  casts the string to a nonbinary string and pads it on the right with spaces to a length of N characters. N  must be at least 1. If N  is less than the length of the input string, the string is truncated to N  characters. No warning occurs for truncation. 

• AS BINARY( N )  is similar but casts the string to a binary string, N  is measured in bytes (not characters), and padding uses 0x00  bytes (not spaces). 

mysql> SET NAMES ’latin1’; mysql> SELECT HEX(WEIGHT_STRING(’ab’ AS CHAR(4))); +-------------------------------------+ | HEX(WEIGHT_STRING(’ab’ AS CHAR(4))) | +-------------------------------------+ | 41422020 | +-------------------------------------+ mysql> SET NAMES ’utf8’; mysql> SELECT HEX(WEIGHT_STRING(’ab’ AS CHAR(4))); +-------------------------------------+ | HEX(WEIGHT_STRING(’ab’ AS CHAR(4))) | +-------------------------------------+ | 0041004200200020 | +-------------------------------------+ 

mysql> SELECT HEX(WEIGHT_STRING(’ab’ AS BINARY(4))); +---------------------------------------+ | HEX(WEIGHT_STRING(’ab’ AS BINARY(4))) | +---------------------------------------+ | 61620000 | +---------------------------------------+ 

The flags  clause currently is unused. 

If WEIGHT_STRING()  is invoked from within the mysql  client, binary strings display using hexadecimal notation, depending on the value of the --binary-as-hex . For more information about that option, see Section 4.5.1, “mysql — The MySQL Command-Line Client” . 

## 12.8.1 String Comparison Functions and Operators 

<img src='content_image/829080.jpg'>

