SQL数据库查询使用正则表达式查询中文

-- unicode(expression)函数返回字符串类型的unicode码
--中文对应的unicode码大致为(应该是精确的):19968-40869


declare @tb table
(
[a] varchar(50) 
)
insert @tb
select '客' union all
select '客' union all
select '中' union all
select 'a' union all
select '/' union all
select '.' union all
select '*' union all
select '@' union all
select '了' union all
select '鹰'

select [a] from @tb where unicode([a]) between 19968 and 40869
go

 

--结果

补充回答:

如果在t-sql中想查看unicode码对应的字符可以用nchar(expression)函数

如:select nchar(19968)

结果:一

 

====================================================================

你的中文是指

字段中包含有中文

还是

字段全是有中文组成的

补充回答:

--> 测试数据:@tb
declare @tb table([name] varchar(10))
insert @tb
select '啊' union all
select '阿' union all
select '做' union all
select '111坐' union all
select '做qqq' union all
select '坐' union all
select '左' union all
select 'aaa' union all
select '。' union all
select '★' union all
select '123' union all
select '座'
--找到包含有汉字的列
select * from @tb where patindex('%[阿-做]%',name)>0
/*
name
----------



111坐
做qqq

(6 行受影响)

*/
--如果找到只有中文的列比较难,除非指定了长度,比如说一位就去点 %%
select * from @tb where patindex('[阿-做]',name)>0

 

unicode([a]) between 19968 and 40869 也可以实现相同的功能,但是效率不高

 

出处:http://wenwen.soso.com/z/q172016737.htm

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值