oracle字符串函数


1. replace,translate

--translate 字符级别的替换
--replace 字符串级别的替换
select replace('abaabbb','ab','c') from dual;--cacbb

select translate('aaabbb','ab','ce') from dual;--ccceee

 

2. concat 字符串连接,等同于 || 

select concat('test', '_concat') from dual;--test_concat
select 'test' || '_concat' from dual; --test_concat

 

3. upper,lower,initcap  指定语言集的方法:NLS_UPPER,NLS_LOWER,NLS_INITCAP

select upper('AaaaAa') from dual; --AAAAAA
select lower('AaaaAa') from dual; --aaaaaa

select initcap('aaaaa') from dual; --Aaaaa
select initcap('aaa aaa') from dual; --Aaa Aaa

 

4.lpad,rpad  字符串填充,如果不指定填充字符,默认为空格

select lpad('aa',10,'0') from dual; --左填充  00000000aa
select rpad('aa',10,'0') from dual; --右填充  aa00000000

 

5. ltrim,rtrim,trim(leading,trailing,both) 字符串修剪,trim只支持单字符修剪? 默认剪去空格

select ltrim('111111111000123000','01') from dual; --从左截掉所有0和1 23000
select rtrim('00012300011111','012') from dual;----从右截掉所有0和1 000123

select trim(leading '0' from '000123000') from dual;  --从头截掉所有的0 123000
select trim(trailing '0' from '000123000') from dual;  --从尾截掉所有的0 000123
select trim(both '0' from '000123000') from dual;  --两边同时截掉所有的0 123

 

6. substr

--substr(char,start,length) 截取char从start开始的长度为length的字符串
select substr('abc',0,1) from dual; --返回a
select substr('abc',1,1) from dual;--start为0和start为1效果相同
select substr('abcdefgs',-5,3) from dual;--如果start为负数,则从倒数第start个字符开始截取  返回def
select substr('abcdefgs',-5) from dual;--如果省略length,则截取start直到结尾的字符串  返回defgs

 

7. regexp_substr,regexp_replace

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM