PL/SQL Substr

The Substr function extract a substring from a string.

Substr syntax

SUBSTR (substring , position, substring_length)

Substr example

 
select substr('My pl/sql substring', 7, 3) from dual;

Result: 'sql'


select substr('My pl/sql substring', 7) from dual;

Result: 'sql substring'


select substr('My pl/sql substring', 1, 9) from dual;

Result: 'My pl/sql' 

Substr example

select s.STUDENT_ID, s.FIRST_NAME, s.LAST_NAME, 
s.CITY, substr(s.CITY, 1,3)  AS SHORT_CITY
from students s;
STUDENT_ID FIRST_NAME LAST_NAME CITY SHORT_CITY
1 Daniel SCOTT New York New
2 Anthony SIMMONS Chicago Chi
3 Sophia THOMPSON Los Angeles Los