The length of the argument may be returned by this function. There are two arguments for the return value, one for the STRING argument and another for the BYTES argument. The length of the string in characters is equal to the length of the string in chars.
If you think so, BYTES_LENGTH is exactly the same as before, but in numbers of bytes instead of characters. The original order ID should have all three functions applied to it.
SELECT order_id,
CHAR_LENGTH(order_id) AS order_id_CHAR,
CHARACTER_LENGTH(order_id) AS order_id_CHARACTER,
BYTE_LENGTH(order_id) AS order_id_BYTE
FROM `orders.orders`;
The function must be called and the column name must be written.
order_id | order_id_CHAR | order_id_CHARACTER | order_id_BYTE |
&&&4592022070101&&& | 19 | 19 | 19 |
&&&4592022070102&&& | 19 | 19 | 19 |
&&&4922022070101&&& | 19 | 19 | 19 |
&&&4922022071201ć&& | 19 | 19 | 20 |
&&&4822022071501&&& | 19 | 19 | 19 |
The functions CHAR_LENGTH() and CHARACTER_LENGTH() both return the same result. As I have mentioned, BYTE_LENGTH() measures the length in bytes. The length in bytes is different from the character length if there are Unicode characters. That’s why it shows a length of 20 bytes in the fourth row. The character “ć“, a Unicode character, somehow got into the order ID.