Oracle 判断表字段里字符串是否含有汉字

我们知道在数据库中,汉字占用两个字节,而其他字符占用一个字节,这样通过两个函数的比较就可以判断出是否有中文,

length计算字符长度,lengthb计算字节长度;

select lengthb('a爱中国'),length('a爱中国') from dual;

第一个返回7,第二个返回4,这样就可以判断有中文了。

另外一种方法采用ascii的方法

oracle--判断字段是不是中文

    在网上找了一种实现方法,试了一下是OK的, 以下语句可以查出包含中文字符的a字段记录 

Oracle_sql代码
  1. select * from A where asciistr(a) like '%\%' and instr(a, '\') <= 0
select * from A where asciistr(a) like '%\%' and instr(a, '\') <= 0;


字符函数 asciistr 功能:返回字符对应的ASCII码,对于非ASCII码转化为Unicode并前置符号'\'


INSTR方法的格式为
INSTR(源字符串, 目标字符串, 起始位置, 匹配序号)

例如:INSTR('CORPORATE FLOOR','OR', 3, 2)中,源字符串为'CORPORATE FLOOR', 目标字符串为'OR',起始位置为3,取第2个匹配项的位置。

 

 

 

select asciistr(prod_name),prod_name,
--INSTR(asciistr(prod_name),'\', 1, 1),
substr(asciistr(prod_name),1,INSTR(asciistr(prod_name),'\', 1, 1)-1),
substr(prod_name,length(substr(asciistr(prod_name),1,INSTR(asciistr(prod_name),'\', 1, 1)-1))+1) 
from C2M_SALE_STOCK_MOBREPORT_DAY where asciistr(prod_name) like '%\%' and instr(prod_name, '\') <= 0 ;

猜你喜欢

转载自blog.csdn.net/zhou279818998/article/details/80915571
今日推荐