「MariaDB」HEX関数で文字列の16進数表現を含む文字列を返す
環境
Windows 10 64 bit
MariaDB 10.6.4
書式
HEX(文字列)
引数に指定した文字列(str)について 1 文字毎に16進数に変換し文字列として取得します。
HEX 関数を使うと引数に指定した文字列を 16 進数に変換し文字列として取得します。
使用例1
引数に文字列を指定します
MariaDB [(none)]> select hex('s') resA, hex('t') resB, hex('stu') resC, hex('SKILL') resD;
+------+------+--------+------------+
| resA | resB | resC | resD |
+------+------+--------+------------+
| 73 | 74 | 737475 | 534B494C4C |
+------+------+--------+------------+
1 row in set (0.001 sec)
MariaDB [(none)]> select hex('s') resA, hex('t') resB, hex('stu') resC, hex('SKILL') resD;
+------+------+--------+------------+
| resA | resB | resC | resD |
+------+------+--------+------------+
| 73 | 74 | 737475 | 534B494C4C |
+------+------+--------+------------+
1 row in set (0.001 sec)
MariaDB [(none)]> select hex('s') resA, hex('t') resB, hex('stu') resC, hex('SKILL') resD; +------+------+--------+------------+ | resA | resB | resC | resD | +------+------+--------+------------+ | 73 | 74 | 737475 | 534B494C4C | +------+------+--------+------------+ 1 row in set (0.001 sec)
使用例2
マルチバイト文字を指定します
MariaDB [(none)]> select hex('本') resA, hex('音楽') resB;
+------+----------+
| resA | resB |
+------+----------+
| 967B | 89B98A79 |
+------+----------+
1 row in set (0.000 sec)
MariaDB [(none)]> select hex('本') resA, hex('音楽') resB;
+------+----------+
| resA | resB |
+------+----------+
| 967B | 89B98A79 |
+------+----------+
1 row in set (0.000 sec)
MariaDB [(none)]> select hex('本') resA, hex('音楽') resB; +------+----------+ | resA | resB | +------+----------+ | 967B | 89B98A79 | +------+----------+ 1 row in set (0.000 sec)