String Functions and Operators This function returns the weight string for the input string. The return value is a binary string that represents the comparison and sorting value of the string. It has these properties: WEIGHT_STRING()  is a debugging function intended for internal use. Its behavior can change without notice between MySQL versions. It can be used for testing and debugging of collations, especially if you are adding a new collation. See Section 10.14, “Adding a Collation to a Character Set” . This list briefly summarizes the arguments. More details are given in the discussion following the list. The input string,  str , is a string expression. If the input is a nonbinary (character) string such as a CHAR ,  VARCHAR , or  TEXT  value, the return value contains the collation weights for the string. If the input is a binary (byte) string such as a  BINARY ,  VARBINARY , or  BLOB  value, the return value is the same as the input (the weight for each byte in a binary string is the byte value). If the input is  NULL , WEIGHT_STRING()  returns  NULL . Examples: 2185 • WEIGHT_STRING( str  [AS {CHAR|BINARY}( N )] [ flags ]) •If  WEIGHT_STRING( str1 )  =  WEIGHT_STRING( str2 ) , then  str1  =  str2  ( str1  and  str2  are considered equal) •If  WEIGHT_STRING( str1 )  <  WEIGHT_STRING( str2 ) , then  str1  <  str2  ( str1  sorts before str2 ) • str : The input string expression. • AS  clause: Optional; cast the input string to a given type and length. • flags : Optional; unused. mysql>  SET @s = _utf8mb4 ’AB’ COLLATE utf8mb4_0900_ai_ci; mysql>  SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s)); +------+---------+------------------------+ | @s | HEX(@s) | HEX(WEIGHT_STRING(@s)) | +------+---------+------------------------+ | AB | 4142 | 1C471C60 | +------+---------+------------------------+ mysql>  SET @s = _utf8mb4 ’ab’ COLLATE utf8mb4_0900_ai_ci; mysql>  SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s)); +------+---------+------------------------+ | @s | HEX(@s) | HEX(WEIGHT_STRING(@s)) | +------+---------+------------------------+ | ab | 6162 | 1C471C60 | +------+---------+------------------------+ mysql>  SET @s = CAST(’AB’ AS BINARY); mysql>  SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s)); +------+---------+------------------------+ | @s | HEX(@s) | HEX(WEIGHT_STRING(@s)) | +------+---------+------------------------+ | AB | 4142 | 4142 | +------+---------+------------------------+ mysql>  SET @s = CAST(’ab’ AS BINARY); mysql>  SELECT @s, HEX(@s), HEX(WEIGHT_STRING(@s)); +------+---------+------------------------+ | @s | HEX(@s) | HEX(WEIGHT_STRING(@s)) | +------+---------+------------------------+ | ab | 6162 | 6162 |