赞
踩
如:统计以下字符串逗号出现次数
- select (length('10,CLARK,MANAGER')-
- length(replace('10,CLARK,MANAGER',',','')))/length(',')
- from dual;
- --返回结果2
- select
- (length('HELLO HELLO HELLO')-
- length(replace('HELLO HELLO HELLO','LL','')))/length('LL')
- ,
- (length('HELLO HELLO HELLO')-
- length(replace('HELLO HELLO HELLO','LL','')))
- from DUAL;
- --返回结果 3 6
如:删除ABCDEFG 中的 ABE
使用translate内置函数
- select
- replace(translate('ABCDEFG','ABE','aaaaa'),'a')
- from DUAL;
- --返回结果CDFG
如:SMITH800,需要分离为 SMITH 800
- select replace(
- translate('SMITH800','0123456789','0000000000'),'0') ,
- to_number(
- replace(
- translate(lower('SMITH800'),
- 'abcdefghijklmnopqrstuvwxyz',
- rpad('z',26,'z')),'z'))
- from dual;
- --返回结果 SMITH 800
- select data
- from test
- where translate(lower(data),
- '0123456789abcdefghijklmnopqrstuvwxyz',
- rpad('a',36,'a')) = rpad('a',length(data),'a');
如 获考虑人名 Stewie Griffifin,你希望得到 S.G.
- select replace(
- replace(
- translate(replace('Stewie Griffin', '.', ''),
- 'abcdefghijklmnopqrstuvwxyz',
- rpad('#',26,'#') ), '#','' ),' ','.' ) ||'.'
- from dual;
-
- --返回S.G.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。