In Oracle/PLSQL, thesubstrfunctions allows you to extract a substring from a string.
The syntax for thesubstrfunction is:
substr( string, start_position, [ length ] )
stringis the source string.
start_positionis the position for extraction. The first position in the string is always 1.
lengthis optional. It is the number of characters to extract. If this parameter is omitted,substrwill return the entire string.
Note:
Ifstart_positionis 0, thensubstrtreatsstart_positionas 1 (ie: the first position in the string).
Ifstart_positionis a positive number, thensubstrstarts from the beginning of the string.
Ifstart_positionis a negative number, thensubstrstarts from the end of the string and counts backwards.
Iflengthis a negative number, thensubstrwill return a NULL value.
Applies To:
- Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
For example:
substr('_yeexunOn优快云',8) char_return 'On优快云' substr('_yeexunOn优快云',10) char_return '优快云' substr('_yeexunOn优快云',8,2) char_return 'On' substr('_yeexunOn优快云',-4,4) char_return '优快云' substr('_yeexunOn优快云',0,7) char_return '_yeexun' substr('_yeexunOn优快云',1,7) char_return '_yeexun' substr('_yeexunOn优快云',0,1) char_return '_' substr('_yeexunOn优快云',1,1) char_return '_' substr('_yeexunOn优快云',0,2) char_return '_y' substr('_yeexunOn优快云',1,2) char_return '_y'