tech on the net
Home About Us Feedback Site Map

Microsoft

Access Excel Word

Database

SQL Oracle / PLSQL SQL Server MySQL MariaDB PostgreSQL

Web Development

HTML CSS Color Picker

Language

C Language

More

ASCII Table Linux UNIX Java Clipart Joke of the Moment

Other Sites

CheckYourMath BigActivities DigMinecraft
Share this page:

Oracle/PLSQL: INSTR Function

Learn how to use the Oracle/PLSQL INSTR function with syntax and examples.

Description

The Oracle/PLSQL INSTR function returns the location of a substring in a string.

Syntax

The syntax for the Oracle/PLSQL INSTR function is:

INSTR( string, substring [, start_position [,  nth_appearance ] ] )

Parameters or Arguments

string is the string to search. string can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.

substring is the substring to search for in string. substring can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.

start_position is the position in string where the search will start. This argument is optional. If omitted, it defaults to 1. The first position in the string is 1. If the start_position is negative, the INSTR function counts back start_position number of characters from the end of string and then searches towards the beginning of string.

nth_appearance is the nth appearance of substring. This is optional. If omitted, it defaults to 1.

Note

  • If substring is not found in string, then the INSTR function will return 0.

Applies To

The INSTR 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 INSTR function examples and explore how to use the INSTR function in Oracle/PLSQL.

For example:

INSTR('Tech on the net', 'e') would return 2; the first occurrence of 'e'
INSTR('Tech on the net', 'e', 1, 1) would return 2; the first occurrence of 'e'
INSTR('Tech on the net', 'e', 1, 2) would return 11; the second occurrence of 'e'
INSTR('Tech on the net', 'e', 1, 3) would return 14; the third occurrence of 'e'
INSTR('Tech on the net', 'e', -3, 2) would return 2