Oracle instr function usage

Source: Internet
Author: User
When I was working on a project over the past few days, I used the instr function of Oracle to solve the problem of user group permission allocation. Now I have a good idea about this function. In OraclePLSQL, The instr function returns the position of the string to be truncated in the source string. Syntax: instr (string1, string2 [, start_position [, nth_appe

When I was working on a project over the past few days, I used the instr function of Oracle to solve the problem of user group permission allocation. Now I have a good idea about this function. In Oracle/PLSQL, The instr function returns the position of the string to be truncated in the source string. Syntax: instr (string1, string2 [, start_position [, nth_appe

When I was working on a project over the past few days, I used the instr function of Oracle to solve the problem of user group permission allocation. Now I have a good idea about this function.

In Oracle/PLSQL,InstrThe function returns the position of the string to be truncated in the source string.

Syntax: instr (string1, string2 [, start_position [, nth_appearance])

String1Source string to be searched in this string.

String2ToString1.

Start_positionRepresentativeString1Where to start searching. This parameter is optional. If omitted, the default value is 1. The string index starts from 1. If this parameter is positive, it is retrieved from left to right. If this parameter is negative, from right to left, the start index of the string to be searched in the source string is returned.

Nth_appearanceIndicates the number of timesString2. This parameter is optional. If omitted, the default value is 1. If it is negative, an error is returned.


Return Value: the position of the searched string.
Note:

If String2 is not found in String1, The instr function returns 0.

Applicable:

  • Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g

Example:

Select instr ('abc', 'A') from dual; -- returns 1
Select instr ('abc', 'bc') from dual; -- returns 2
Select instr ('abc abc', 'A', 1, 2) from dual; -- return 5
Select instr ('abc', 'bc',-) from dual; -- returns 2
Select instr ('abc', 'D') from dual; -- returns 0

Note: You can also use this function to check whether String1 contains String2. If 0 is returned, it means it does not contain; otherwise, it means it contains.

========================================================== ========================================================
Instr usage in Oracle

The Instr function in Oracle is used in the project. By the way, I learned this knowledge carefully.

In Oracle, you can use the Instr function to determine whether a string contains specified characters.

Its syntax is:
Instr (string, substring, position, occurrence)
Where

String: indicates the source string;

Substring: represents the substring to be searched in the intelligent source string;

Position: indicates the start position of the search. this parameter is optional. The default value is 1;

Occurrence: specifies the number of substrings that appear from the source character list. This parameter is optional. The default value is 1;
If the position value is negative, it indicates searching from right to left.
Return Value: the position of the searched string.

For Instr functions, we often use this method to find the position of the specified substring from a string.

For example:

SELECT Instr ('Hello word', 'O',-1, 1) "String" FROM Dual:

Instring
----
8

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.