SQL数据库查询使用正则表达式查询中文
2012-06-28 12:07
281 查看
-- 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
--中文对应的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
相关文章推荐
- Python如何使用正则表达式匹配中文
- MySQL知识(十一)——使用正则表达式查询
- 使用政策表达式查询sql数据库
- mysql中使用正则表达式查询
- JS使用正则表达式截取字符串中的中文
- mysql 使用正则表达式查询
- 中文正则表达式初步使用
- Oracle SQL多行字符串拆分使用层次查询(connect by)、正则表达式
- Java源码-使用正则表达式查询匹配记录
- [sqlite3]_[初级]_[使用正则表达式REGEXP查询]
- PHP中使用正则表达式提取中文实现笔记
- 使用Android Studio查找文件中含有中文字符串位置(正则表达式)
- Lucene使用正则表达式查询
- 使用Android Studio查找文件中含有中文字符串位置(正则表达式)
- MySQL中使用正则表达式查询
- PHP使用正则表达式匹配中文,有部分匹配不出来的解决办法
- Visual studio 替换使用正则表达式 查询http
- Oracle中查询使用正则表达式函数REGEXP_LIKE
- 使用正则表达式获取Sql查询语句各项(表名、字段、条件、排序)
- 使用c#的正则表达式验证中文字符