totn Oracle Functions

Oracle / PLSQL: INSTRC Function

This Oracle tutorial explains how to use the Oracle/PLSQL INSTRC function with syntax and examples.

Description

The Oracle/PLSQL INSTRC function returns the location of a substring in a string, using Unicode complete characters.

Syntax

The syntax for the INSTRC function in Oracle/PLSQL is:

INSTRC( string, substring [, start_position [, th_appearance ] ] )

Parameters or Arguments

string
The string to search. string can be CHAR, VARCHAR2, NCHAR, or NVARCHAR2. string can not be CLOB or NCLOB.
substring
The substring to search for in string. substring can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.
start_position
Optional. The position in string where the search will start. If omitted, it defaults to 1. The first position in the string is 1. If the start_position is negative, the INSTRC function counts back start_position number of characters from the end of string and then searches towards the beginning of string.
nth_appearance
Optional. The nth appearance of substring. If omitted, it defaults to 1.

Returns

The INSTRC function returns a numeric value. The first position in the string is 1.
If substring is not found in string, then the INSTRC function will return 0.
If string is NULL, then the INSTRC function will return NULL.
If substring is NULL, then the INSTRC function will return NULL.

Note

Applies To

The INSTRC function can be used in the following versions of Oracle/PLSQL:

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

Example

Let's look at some Oracle INSTRC function examples and explore how to use the INSTRC function in Oracle/PLSQL.

For example:

INSTRC('TechOnTheNet.com', 'e')
Result: 2   (the first occurrence of 'e')

INSTRC('TechOnTheNet.com', 'e', 1, 1)
Result: 2   (the first occurrence of 'e')

INSTRC('TechOnTheNet.com', 'e', 1, 2)
Result: 9   (the second occurrence of 'e')

INSTRC('TechOnTheNet.com', 'e', 1, 3)
Result: 11  (the third occurrence of 'e')

INSTRC('TechOnTheNet.com', 'e', -3, 2)
Result: 9