The Substring function in SQL is used to grab a portion of the stored data. This
function is called differently for the different databases:
- MySQL: SUBSTR( ), SUBSTRING( )
- Oracle: SUBSTR( )
- SQL Server: SUBSTRING( )
The most frequent uses are as follows (we will use SUBSTR( ) here):
SUBSTR(str,pos): Select all characters from <str> starting with position <pos>. Note that this syntax is not supported in SQL Server.
SUBSTR(str,pos,len): Starting with the <pos>th
character in string <str> and select the next <len> characters.
Assume we have the following table:
SELECT SUBSTR(store_name, 3)
WHERE store_name = 'Los Angeles';
WHERE store_name = 'San Diego';
Next: SQL INSTR
|| Copyright © 2013 1keydata.com All Rights Reserved.