Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Instr () function in Oracle

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I. Format of instr() function (commonly known as character search function)

Format 1: instr( string1, string2 )

/ instr(source string, destination string)

Format 2: instr( string1, string2 [, start_position [, nth_appearance ] ] )

/ instr(source string, destination string, start position, match ordinal)

Parsing: The value of string2 is to be found in string1, starting from the value given by start_position (i.e.: position) and searching string1 to retrieve the nth_appearance (how many) times string2 appears.

Note: In Oracle/PLSQL, the instr function returns the position of the string to intercept in the source string. Search only once, that is, from the beginning of the character to the end of the character.

II. Examples

form in

1. select instr ('helloworld ',' l') from dual; --default to the location where the "l" first appears

2. select instr ('helloworld ',' lo') from dual; --in "lo", where the "l" begins

3. select instr ('helloworld ','wo') from dual; --where "w" begins to appear

Format II

1、select instr('helloworld','l',2,2) from dual;

--Start at position 2(e) of helloworld and find the position of the second occurrence of "l"

2、select instr('helloworld','l',3,2) from dual;

--Start at position 3(l) of helloworld and find the position of the second occurrence of "l"

3、select instr('helloworld','l',4,2) from dual;

--Start at position 4(l) of helloworld and find the position of the second occurrence of "l"

4、select instr('helloworld','l',-1,1) from dual;

--Start at the 1(d) last position of "helloworld" and look back to the position of the first occurrence of "l"

5、select instr('helloworld','l',-1,2) from dual;

--Start at the penultimate 1(d) position of "helloworld" and look back for the second occurrence of "l"

6、select instr('helloworld','l',2,3) from dual;

--Start at position 2(e) of helloworld and find the position of the third occurrence of "l"

7、select instr('helloworld','l',-2,3) from dual;

--Start at the penultimate position of "helloworld" and look back to the position of the third occurrence of "l"

Note: Fuzzy query like and instr() functions have the same query effect:

select from table where colName like '%helloworld%';

select from table where instr(colName ,'helloworld')>0; --The two statements have the same effect

Example:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report