1-- ORACLE substr(string, start, [, length ])
2SELECT substr('Hello World', 4, 5) FROM DUAL; -- lo Wo
3SELECT substr('Hello World', 4) FROM DUAL; -- lo World
4SELECT substr('Hello World', -3) FROM DUAL; -- rld
5SELECT substr('Hello World', -3, 2) FROM DUAL; -- rl
1SUBSTR(string, :START_POS, :SUBSTR_LENGTH);
2
3SELECT SUBSTR('ABCDEFG',3,4) FROM DUAL;
4--OUTPUT: CDEF
1-- ORACLE SQL - Get the 2 digits at the right end of a string
2SELECT SUBSTR('TN0001234567890345',-2) FROM DUAL;
3
4
1/*Using SUBSTR in Oracle (Example from hackerrank.com): */
2
3/*Simple select query...*/
4SELECT DISTINCT city
5FROM station
6
7/*Using WHERE and SUBSTR to find (distinct) cities in station table that begin
8as well as end with a vowel.*/
9WHERE SUBSTR(city,1,1) IN ('A','E','I','O','U')
10 AND substr(city,-1) IN ('a','e','i','o','u');
11
12/*Parameters for SUBSTR (Substring) in order are as follows:
13String, Start, Length.*/