In Oracle, the substr() function is used to intercept strings. Setting the function parameters can specify the length of the intercepted string and the interception position. The syntax is "substr(string string, int a, int b)" or "substr(string string,int a)".
The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.
1) substr function format (commonly known as: character interception function)
Format 1:
substr(string string, int a, int b);
1, string The string to be intercepted
2. a. The starting position of interception, (0,1 are both represented as the first element)
3. b. The length of the string to be intercepted
Format 2:
substr(string string, int a) ;
1. string The string to be intercepted
2. a from the ath element to the last element
2) Example analysis
1、select substr('HelloWorld',0,3) value from dual; //返回结果:Hel,截取从“H”开始3个字符 2、select substr('HelloWorld',1,3) value from dual; //返回结果:Hel,截取从“H”开始3个字符 3、select substr('HelloWorld',2,3) value from dual; //返回结果:ell,截取从“e”开始3个字符 4、select substr('HelloWorld',0) value from dual; //返回结果:HelloWorld,截取所有字符 5、select substr('HelloWorld',1) value from dual; //返回结果:HelloWorld,截取所有字符 6、select substr('HelloWorld',2) value from dual; //返回结果:elloWorld,截取从“e”开始之后所有字符
Summary If a is a negative number, it represents the last few elements, and then take b elements. If not enough, just go to the last one.
The example is as follows:
Recommended tutorial: "Oracle Video Tutorial"
The above is the detailed content of What is the usage of substr in oracle. For more information, please follow other related articles on the PHP Chinese website!