The SUBSTRING function, operating like SUBSTR, extracts a character string having the length of substring_length from a position, position, within character string, string, and returns it.
If a negative number is specified to the position value, the SUBSTRING function calculates the position from the beginning of the string. And SUBSTR function calculates the position from the end of the string. If a negative number is specified to the substring_length value, the SUBSTRING function handles the argument is omitted, but the SUBSTR function returns NULL.
SUBSTRING( string, position [, substring_length])
SUBSTRING( string FROM position [FOR substring_length] )
string :
• bit string
• character string
• NULL
position :
• integer
• NULL
substring_length :
• integer
SELECT SUBSTRING('12345abcdeabcde', -6 ,4), SUBSTR('12345abcdeabcde', -6 ,4);
============================================
'1234' 'eabc'
SELECT SUBSTRING('12345abcdeabcde', 16), SUBSTR('12345abcdeabcde', 16);
============================================
'' NULL
SELECT SUBSTRING('12345abcdeabcde', 6, -4), SUBSTR('12345abcdeabcde', 6, -4);
============================================
'abcdeabcde' NULL