「MariaDB」CHAR_LENGTHで文字列の長さを文字数単位で取得

環境
Windows 10 64 bit
MariaDB 10.6.4
書式
CHAR_LENGTH(文字列)
CHAR_LENGTH 関数は引数に指定した文字列の長さを文字数単位で取得するために使用します。

使用例1
引数に指定した文字列( str )の長さを文字数単位で取得します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> select length('Study2021') resA, char_length('Study2021') resB;
+------+------+
| resA | resB |
+------+------+
| 9 | 9 |
+------+------+
1 row in set (0.066 sec)
MariaDB [(none)]> select length('Study2021') resA, char_length('Study2021') resB; +------+------+ | resA | resB | +------+------+ | 9 | 9 | +------+------+ 1 row in set (0.066 sec)
MariaDB [(none)]> select length('Study2021') resA, char_length('Study2021') resB;
+------+------+
| resA | resB |
+------+------+
|    9 |    9 |
+------+------+
1 row in set (0.066 sec)

使用例2
マルチバイト文字の場合も 1 文字は 1 つとしてカウントされます。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
MariaDB [(none)]> select length('あいうえお') resA, char_length('あいうえお') resB;
+------+------+
| resA | resB |
+------+------+
| 10 | 5 |
+------+------+
1 row in set (0.026 sec)
MariaDB [(none)]> select length('あいうえお') resA, char_length('あいうえお') resB; +------+------+ | resA | resB | +------+------+ | 10 | 5 | +------+------+ 1 row in set (0.026 sec)
MariaDB [(none)]> select length('あいうえお') resA, char_length('あいうえお') resB;
+------+------+
| resA | resB |
+------+------+
|   10 |    5 |
+------+------+
1 row in set (0.026 sec)

 

MariaDB

Posted by arkgame