The SQL Substring feature is a function that enables parts of strings to be accessed.
For example, the function SUBSTRING('212-555-1234', 9 , 4) returns:
'1234'
It returns 4 characters starting in position 9.
Substring is useful when accessing a column that consists of meaningful subcomponents, such as a telephone number that contains area code, prefix and phone number body.
SQL SUBSTRING is used as follows.
SQL SUBSTRING Syntax
SQL SUBSTRING Example
This example returns three characters of the region_name column starting in position 2.
Here are the contents of the table:
Table: REGION
region_nbr | region_name |
100 | East Region |
200 | Central Region |
300 | Virtual Region |
400 | West Region |
This SQL Statement with SUBSTRING is executed:
Here is the result.
region_name | substring_name |
East Region | ast |
Central Region | ent |
Virtual Region | irt |
West Region | est |
Advertisements:
Infogoal.com is organized to help you gain mastery.
Examples may be simplified to facilitate learning.
Content is reviewed for errors but is not warranted to be 100% correct.
In order to use this site, you must read and agree to the
terms of use, privacy policy and cookie policy.
Copyright 2006-2020 by Infogoal, LLC. All Rights Reserved.