SQL Query to find the position of a given character in field

There are following way to find the position of a given character in a field in Oracle database.

    • Here we are fetch the position of a given character(s) in a field.
    • There first we have created one Employee table.
    • In that table there are 3 column Id, Name, Address field.

               Select * from Employee;

fetch the position of a given character

Use INSTR function :-

It is use for search string for substring. This function returns a numeric value. The first position of the string is start from 1. If the specific substring is not found in string, then the INSTR function will return 0.

Select INSTR(Name, ‘b’) as position from Employee;

position of a given character in field

In the first row we get position of ‘b’ character in name field at position 2.
In the second row we get the position of ‘b’ character in name field is 0 because there are not ‘b’ character in name string.