Oracle Database SUBSTR


Example

SUBSTR retrieves part of a string by indicating the starting position and the number of characters to extract

SELECT SUBSTR('abcdefg',2,3) FROM DUAL;

returns:

bcd

To count from the end of the string, SUBSTR accepts a negative number as the second parameter, e.g.

SELECT SUBSTR('abcdefg',-4,2) FROM DUAL;

returns:

de

To get the last character in a string: SUBSTR(mystring,-1,1)