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函数
select rtrim('5151561651','1253') as 结果 from dual; 51515616
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。