一个汉字是不是占两个字符位置
-------------
一个汉字是一个“字符”,2个字节16位。
全角/半角都是一个字符。
加两个下划线就显示了刘晨和刘好东
-------------
不可能,1个下划线_表示任意一个字符,2个__则表示两个任意字符,所以不能显示刘晨。同时显示(不用%):
select name from student where name like '刘_' or name like '刘__'
如果只想要三个字的名字呢,而不显示两个汉字的
-------------
select name from student where name like '刘__'
-------------
一个汉字是一个“字符”,2个字节16位。
全角/半角都是一个字符。
加两个下划线就显示了刘晨和刘好东
-------------
不可能,1个下划线_表示任意一个字符,2个__则表示两个任意字符,所以不能显示刘晨。同时显示(不用%):
select name from student where name like '刘_' or name like '刘__'
如果只想要三个字的名字呢,而不显示两个汉字的
-------------
select name from student where name like '刘__'
返回给定字符串表达式的字符(而不是字节)个数,其中不包含尾随空格。语法
LEN ( string_expression )
要计算的字符串表达式。DATALENGTH
返回任何表达式所占用的字节数。语法
DATALENGTH ( expression )
以上两个函数是计算字符数/字节数
declare @t table(Name nvarchar(10))
insert @t select '刘晨'
union select '刘好东'select * from @t where Name like '刘__'
select * from @t where Name like '刘_'
(所影响的行数为 2 行)Name
----------
刘好东(所影响的行数为 1 行)Name
----------
刘晨(所影响的行数为 1 行)
用char空格都会占一个字符
insert @t select '刘晨'
union select '刘好东'select * from @t where Name like '刘__' --显示2行
select * from @t where Name like '刘_' --显示1行
这是因为你用了char类型
insert @t select '刘晨'
union select '刘好东'select * from @t where Name like '刘__' --显示2行
select * from @t where Name like '刘_' --显示1行
这是因为你用了char类型