PostgreSQL , Oracle , 字符长度 , 字节长度 , 空格 , varchar , char , 定长 , 变长 , 末尾追加空格
由于多字节字符的存在,所以在数据库应用中,通常会出现两种计算字符串长度的需求:
1、计算字符串个数
2、计算字节数
在不同的数据库中,使用的函数不一样。
<a href="https://stackoverflow.com/questions/17062065/how-to-select-data-items-of-a-certain-length">https://stackoverflow.com/questions/17062065/how-to-select-data-items-of-a-certain-length</a>
Assuming you want the length in characters, the function names vary with RDBMS;
If you want the length in bytes, it's instead;
For example, selecting all rows with names longer than 10 characters in MySQL would be;
以PostgreSQL为例。
1、定长,末尾自动追加空格,计算字符长度时,不计算末尾的空格。计算字节长度时,计算空格。
2、变长,末尾不追加空格,计算字符长度时,计算空格。计算字节长度时,计算空格。