Oracle implementation indexof similar summary ____oracle

Source: Internet
Author: User

In Oracle/plsql, the InStr function returns the position of the string to be intercepted in the source string.

The syntax is as follows: InStr (string1, string2 [, Start_position [, Nth_appearance]])

String1 the source string to find in this string.

String2 the string to find in the string1.

The start_position represents where the string1 starts looking. This parameter is optional, if omitted defaults to 1. The string index starts at 1. If this parameter is positive, retrieves from left to right, if this parameter is negative, retrieves from right to left, and returns the starting index of the string to find in the source string.

The nth_appearance represents the string2 to find the first occurrence. This parameter is optional, and if omitted, the default is 1. If the system is negative, the error occurs.

Attention:

If String2 is not found in String1, the InStr function returns 0. Apply to:

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

Select InStr (' abc ', ' A ') from dual; --Return 1
Select InStr (' abc ', ' BC ') from dual; --Return 2
Select InStr (' abc abc ', ' A ', 1,2) from dual; --Return 5
Select InStr (' abc ', ' BC ', -1,1) from dual; --Return 2
Select InStr (' abc ', ' d ') from dual; --Return 0

Substr and InStr nested to achieve indexof similar functionality

Eg: Garden Professional priority Tel: 07713212335-803 Get the telephone number, by ' Telephone: ' to be separated.

Select substr (' Garden Professional priority phone: 07713212335-803 ', InStr (' Garden Professional priority Tel: 07713212335-803 ', ' Tel: ') +3,20) from dual;

Related Article

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.