Home > Database > Oracle > body text

What is the usage of substr in oracle

WBOY
Release: 2022-03-01 17:01:20
Original
48057 people have browsed it

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)".

What is the usage of substr in oracle

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

What is the usage of substr in oracle

1) substr function format (commonly known as: character interception function)

Format 1:

substr(string string, int a, int b);
Copy after login

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) ;
Copy after login

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”开始之后所有字符
Copy after login

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:

What is the usage of substr in oracle

What is the usage of substr in oracle

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!