Oracle 中提取汉字数据去除非汉字数据

--提取汉字,去掉非汉子数据

--创建函数
/*使用ASCII码来区分中文和其它字符,中文的ASCII码值的范围是45217~63486,
根据这个来实现,我们就需要使用ORACLE中的函数ASCII,用它来返回ASCII值。*/
create or replace function FUNC_CHINESE(custName varchar2) return varchar2 is
  Result varchar2(100);
  tmp_custName varchar2(100);
  count_str number;
  i number:=1;
  str_ascii number;
  current_char varchar2(10);
begin
     select length(custName) into count_str from dual;
     while i<count_str loop
        current_char:=substr(custName,i,1);
        select ASCII(current_char) into str_ascii from dual;
         if str_ascii>45216 then
            tmp_custName:=tmp_custName||current_char;
         end if;
         i:=i+1;
     end loop;
     Result:=tmp_custName;
  return(Result);
end FUNC_CHINESE;

--创建测试数据
create table tests(
txt varchar2(200)
);

insert into tests (txt)
values('你a好,你1吃D饭S了s');


--测试函数
select FUNC_CHINESE(txt) from tests

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值