日期:2014-05-17  浏览次数:21592 次

oracle 正则表达式 匹配汉字
本帖最后由 yuzhong218 于 2012-09-21 13:03:11 编辑
请问oracle正则表达式只是单纯的匹配汉字应该怎么写啊?比如大家好"和"大家好!"和"大家好!123"和"大家好abc"结果就只要第一个,后面的不显示,这样的正则表达式应该怎么写啊?或者单纯的sql能够实现也可以
------解决方案--------------------

--判斷全為雙字節就可以了
with t(col) as(
select '大家好' from dual
union all select '大家好!' from dual
)
select col from t where length(col)*2=lengthb(col);

------解决方案--------------------
引用:
不可以啊,因为有可能有全角字符


with t(col) as(
select '大家好' from dual
union all select '大家好!' from dual
union all select '大家好‘' from dual
)
select col from t where length(col)*2=lengthb(col)
and regexp_like(col,'^[^[:punct:]]*$');
/*

COL                                                                             
--------                                                                        
大家好  
*/