select * from student where sname like '__力',为何结果为空?
==================>改为:
select * from student where sname like '_力'

解决方案 »

  1.   

    用select * from student where sname like '%力'
    因为_代表单个字符
    '__u'的意思是u前面可以有任意两个字符,而它前面有li,所以是对的,可以查出liu来'__力'的意思是“力”前面可以有任意两个字符,而它前面有“张”,所以是不对的,是查不出来因为在数据库中汉字和字符都是单个字符,所以统一用%就ok
      

  2.   

    declare @t table(id varchar(50),sname varchar(50))insert @t select '200215121','张力'
    union select '200215122','liu'
    select * from @t where sname like '_力'--结果 
    id sname
    200215121   张力
      

  3.   

    declare @t table(id varchar(50),sname varchar(50))insert @t select '200215121','张力'
    union select '200215122','liu'
    select * from @t where sname like '__u'--结果 
    id sname
    200215122       liu
    select * from @t where sname like '_u'
    --结果为空
      

  4.   

    _(通配符 — 匹配一个字符)
    匹配任意单个字符,并且可以被用作前缀或后缀。
    所以在查询'张力'的时候,用一个_,
    在查询liu的时候,用2个_