substr 函数

格式1: substr(string string, int a, int b);

1、string 需要截取的字符串 
2、a 截取字符串的开始位置(注:当a等于0或1时,都是从第一位开始截取)
3、b 要截取的字符串的长度
select substr('helloworld','0','4') as 结果 from dual; hell
select substr('helloworld','1','4') as 结果 from dual; hell
select substr('helloworld','2','4') as 结果 from dual; ello


格式2:substr(string string, int a) ;

1、string 需要截取的字符串
2、a 可以理解为从第a个字符开始截取后面所有的字符串。
select substr('helloworld','0') as 结果 from dual; helloworld
select substr('helloworld','1') as 结果 from dual; helloworld
select substr('helloworld','2') as 结果 from dual; elloworld


oracle中0、1都从第一个开始

如果a为负数,则b失效,从后面开始数

select substr('helloworld','-1') as 结果 from dual; d
select substr('helloworld','-1','4') as 结果 from dual; d
两者结果都为d


trim函数

1.rtrim 右侧开始,包含’1253'中任意一个都删除

select rtrim('5151561651','1253') as 结果 from dual; 51515616


2.ltrim 左侧开始,包含’1253'中任意一个都删除

select ltrim('5151561651','1253') as 结果 from dual; 61651


3.trim 删除两侧空格

select trim(' 1253 ') as 结果 from dual; 1253


4.从两侧开始,与both一致

select trim('2'from '22342') as 结果 from dual; 34
select trim(both '2'from '22342') as 结果 from dual; 34


5.leading 从头部

select trim(leading '2'from '22342') as 结果 from dual; 342


6.trailing 从尾部

select trim(trailing '2'from '22342') as 结果 from dual; 342