oracle ^]字符,oracle数据中特殊字符处理

最近数据处理时经常发现有数字中含有大量字符,执行过程报“ORA-01722: invalid number”异常,整理了一下,可以有以下几种方法去除:

1、replace 用法简单,写法较复杂,只能处理已知字符

With test_table1 As (

Select 1 seq_num, '2134?654?ag d35' strings From dual

Union All

Select 2 seq_num, '651 354a g5 dd21' strings From dual

)

Select seq_num, Replace(Replace(Replace(Replace(Replace(strings, '?', ''), 'a', ''), 'g', ''), 'd', ''), ' ', '')

From test_table1;

---执行结果

1    213465435

2    651354521

2、translate 用法简单,写法简单,只能处理已知字符,字符串、待查找字符,替换字符,均不能为null,否则返回null,字符串按查找顺序替换,若无则去除

With test_table1 As (

Select 1 seq_num, '2134?654?ag d35' strings From dual

Union All

Select 2 seq_num, '651 354a g5 dd21' strings From dual

)

Select seq_num,

translate(strings, '1asdfasg ?', '1')

From test_table1;

---执行结果

1    213465435

2    651354521

3、regexp_replace 正则表达式 增强型replace 参数多,可根据正则式处理所有字符

With test_table1 As (

Select 1 seq_num, '2134?654?ag d35' strings From dual

Union All

Select 2 seq_num, '651 354a g5 dd21' strings From dual

Union All

Select 3 seq_num, '2134654?ag d35' strings From dual

Union All

Select 4 seq_num, '16?54?aasdgf78as' strings From dual

Union All

Select 5 seq_num, '16?!@#$%^&*()~:"+_?>

)

Select seq_num,

regexp_replace(strings, '[^0-9]', '')

From test_table1;

---执行结果

1    213465435

2    651354521

3    213465435

4    165478

5    168

注:这些是以前所写,现转移到OSC,博客原文:外链网址已屏蔽

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值