1-- For Oracle only
2
3-- syntax
4SUBSTR(<main-string>,1,<number-of-characters>)
5
6-- example
7SUBSTR('Useless stuff',1,10) -- OUTPUT: Useless st
8
9-- practical example
10SELECT SUBSTR('Useless stuff',1,10)
11FROM DUAL;
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.*/