Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Get char at position in field

Tags:

sql

In SQL Server you can use SUBSTRING

SELECT SUBSTRING('hello', 3, 1)

Take care: index is 1-based.


In Oracle, use SUBSTR

Syntax is SUBSTR(<string to parse>,<start position>,(<length>)) - i.e.

SELECT SUBSTR('hello',3,1)

Start position and length are one-, not zero-based. Zero is accepted, but will be interpreted as 1.


following Query will search from specific index for char and will return result

select * from tbPatientMaster
where SUBSTRING (fname,CHARINDEX ('.',fname,0)+1,LEN (fname)) like 'a%'