mysql substring/left 命令未返回正确的字符数
mysql substring/left command isnt returning correct number of characters
我正在执行以下语句:
select left(column,400) from table into outfile test;
我也尝试过使用子字符串函数(结果相同)。
当我去下载文件并得到一个字符数时:
wc -c < test
我得到 409 个字符作为 return。
谁来帮我解决为什么我的计数不正确?
数据库table设置为utf8,列为longtext。
当我运行以下时,它仍然没有给我正确的字符长度:
select length(left(column, 400) from table where id in (1,2,3,4);
+-----------------------------+
| length(left(column,400)) |
+-----------------------------+
| 402 |
| 403 |
| 412 |
| 401 |
+-----------------------------+
命令 wc -c
计数 字节 ,尽管用于开关的字符。使用 UTF-8 格式的数据库,mysql left
正在计算 个字符 。由于 UTF-8 每个字符可以使用超过 1 个字节,因此我预计 column
中的前 400 个字符包括占用 2 个字节的 8 个字符(如果某些字符占用 3 个字节,则少于 8 个)。最后可能还有一个换行符。
我正在执行以下语句:
select left(column,400) from table into outfile test;
我也尝试过使用子字符串函数(结果相同)。
当我去下载文件并得到一个字符数时:
wc -c < test
我得到 409 个字符作为 return。
谁来帮我解决为什么我的计数不正确?
数据库table设置为utf8,列为longtext。
当我运行以下时,它仍然没有给我正确的字符长度:
select length(left(column, 400) from table where id in (1,2,3,4);
+-----------------------------+
| length(left(column,400)) |
+-----------------------------+
| 402 |
| 403 |
| 412 |
| 401 |
+-----------------------------+
命令 wc -c
计数 字节 ,尽管用于开关的字符。使用 UTF-8 格式的数据库,mysql left
正在计算 个字符 。由于 UTF-8 每个字符可以使用超过 1 个字节,因此我预计 column
中的前 400 个字符包括占用 2 个字节的 8 个字符(如果某些字符占用 3 个字节,则少于 8 个)。最后可能还有一个换行符。