The HEX function returns a decimal string if a hexadecimal string is specified as an argument; it returns a hexadecimal string if a decimal string is specified as an argument. If a number is specified as an argument, it returns a value like CONV(num, 10, 16).
HEX(str)
HEX(num)
SELECT HEX('ab'), HEX(128), CONV(HEX(128), 16, 10);
hex('ab') hex(128) conv(hex(128), 16, 10)
==================================================================
'6162' '80' '128'