Now the SQL Tutorial will guide us that the SQL Substring function in SQL is used to grab a
portion of the stored data. SQL Substring function is called
differently for the different databases:
The most frequent uses are as follows (we will use SUBSTR() here):
SUBSTR(str,pos): Select all characters from <str>
starting with
position <pos>.
Important note is that this syntax of SQL Substring is not supported in SQL Server. The below code
sample is ORACLE based substring.
SUBSTR(str,pos,len): Starting with the <pos> character
Position in
string <str> and select the next
<len> characters
Length.
Assume we have the following table:
Table:
Employees
| FirstName |
LastName |
Email |
DOB |
Phone |
| Austin |
Hennery |
austin.it@gamail.com |
24/11/1978 |
446 102-2222 |
| Creston |
Narvon |
narvon_crest@hotmail.com |
22/04/1976 |
443 325-4545 |
| Kate |
Bladen |
kbladen@usa.net |
01/05/1980 |
326 503-3232 |
| Angela |
Julie |
julieee@yahoo.co.uk |
11/12/1977 |
326 323-8888 |
| Bobbi |
Ferguson |
bobi123@kiwibox.com |
10/02/1970 |
506 252-9875 |
| Cute |
Alfa |
cafa@gmail.com |
19/05/1972 |
506 272-4566 |