The WEIGHT_STRING() function returns a binary string representing the sort and compare value of "String".
A lower-scoring string means that the string will appear before a higher-scoring string when sorted.
If "String" is a non-binary character string (CHAR, VARCHAR or TEXT), WEIGHT_STRING() returns the collation weight of "String".
If "String" is a binary string (BINARY, VARBINARY or BLOB), the return value is equal to the input value because the weight is equal to the byte value.
The optional "Format" clause allows "String" to be converted to a binary or non-binary string. The length can be determined:
AS BINARY(length) measures the length in bytes instead of characters and right pads with 0x00 bytes to the desired length.
AS CHAR(length) measures the length in characters and pads right with spaces to desired length.
The length for "Format" must be at least 1. If the specification is less than the length of "String", the "String" will be truncated.
The optional "Level" clause specifies that the return value should contain weights for specific sorting levels.
The level identifier can be either a single integer, a comma-separated list of integers, or a series of integers separated by a hyphen. Spaces are ignored. Depending on the sorting, the numbers can be between 1 and a maximum of 6 and must be listed in ascending order.
If the "Level" clause is not specified, a default value of 1 to the maximum is assumed for sorting.
If "Level" is specified without using a range, an optional modifier "Sorting" is allowed:
ASC: The default, it returns the weights without modification.
DESC: Returns a bitwise inverted weight.
REVERSE: Returns a weight in reverse order.
If the value of "String" is NULL, the WEIGHT_STRING() function returns NULL.