Home >Database >Mysql Tutorial >Oracle的substr函数简单用法

Oracle的substr函数简单用法

PHP中文网
PHP中文网Original
2016-06-07 17:46:041361browse

substr(字符串,截取开始位置,截取长度) //返回截取的字

substr('Hello World',0,1) //返回结果为 'H'  *从字符串第一个字符开始截取长度为1的字符串

substr('Hello World',1,1) //返回结果为 'H'  *0和1都是表示截取的开始位置为第一个字符

substr('Hello World',2,4) //返回结果为 'ello'

substr('Hello World',-3,3)//返回结果为 'rld' *负数(-i)表示截取的开始位置为字符串右端向左数第i个字符

测试:

select substr('Hello World',-3,3) value from dual;

 

附:java中substring(index1,index2)的简单用法

作用:从字符串索引(下标)为index1的字符开始截取长度为index2-index1 的字符串。

String str="Hello World";

System.out.println(str.substring(0,5));

打印结果为:Hello


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn