SQL Substrings, SQL Tutorial, Global Guide Line Technology.
Forum | Blog |


Basic SQL Guide.           
SQL Introduction.               
 What is Table?                  
 SQL Create Table.            
 SQL Insert Statement.      
 SQL Select Keyword.        
 SQL Order by clause.        
 SQL Count Statement.      
 SQL Group By Clause.      
 SQL Having Clause.          
 SQL Alias Tables.             
 SQL Join Tables.              
 SQL Outer Join.               
 SQL Update Statement.   
 SQL Delete Statement.    
 SQL Distinct Keyword.      
 SQL Where Keyword.       
 SQL And Or Keyword.      
 SQL In Keyword.              
 SQL Between Keyword.   
 SQL Like Keyword.          
 SQL Functions.                
 SQL Concatenate.           
 SQL Substrings.
 SQL Trim Function.         
 SQL Constraints.              
 SQL Primary Key.            
 SQL Foreign Key.            
 SQL Create Views.           
 SQL Create Index.           
 SQL Alter Table.             
 SQL Drop Table.             
 SQL Truncate Table.      
 SQL Summary.                

SQL Tutorial >> SQL Substrings.

     Back             Next     

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:

Syntax for SQL Substring Function


Oracle:     SUBSTR() 


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

Examples of SQL Substring Function

FROM Employees
WHERE FirstName = 'Creston';

Result of SQL Substring Function Example


SELECT SUBSTR(FirstName,2,5)
FROM Employees
WHERE FirstName = 'Creston';

Result of SQL Substring Function Example


     Back             Next     

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2022 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 371 visitors are online now