4个字符
字符串的长度:
长度的单位为字符。一个多字节字符算作一个单字符。
MySQL字符串函数:
对于一个包含五个二字节字符集, LENGTH()返回值为 10, 而CHAR_LENGTH()的返回值为5。
也就是说:
对于一个汉字和一个字母都是一个字符。<wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">遵循CHAR和VARCHAR定义规范。</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">也与数据库本身设置的字符集有关。</span><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">mysql的char和varchar字段不区分unicode</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">还是别的什么编码,统统按照ascii来存,</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">所以一个汉字占用2个字节。</span><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">CHAR和VARCHAR类型类似,</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">但它们保存和检索的方式不同。</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">它们的最大长度和是否尾部空格被保留等方面也不同。</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">在存储或检索过程中不进行大小写转换。</span><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">CHAR和VARCHAR类型声明的长度表示你想要保存的最大字</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">符数。例如,CHAR(30)可以占用30个字符。</span><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">CHAR列的长度固定为创建表时声明的长度。</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">长度可以为从0到255的任何值。当保存CHAR值时,</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">在它们的右边填充空格以达到指定的长度。当检索到CHAR值时,</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">尾部的空格被删除掉。在存储或检索过程中不进行大小写转换。</span><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><br style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">VARCHAR列中的值为可变长字符串。</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">长度可以指定为0到65,535之间的值。(</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">VARCHAR的最大有效长度由最大行大小和使用的字符集确定。</span><wbr style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px"><span style="color:rgb(102,102,102); font-family:宋体; font-size:14px; line-height:24px">整体最大长度是65,532字节)。</span> </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>