SUBSTRING()
Anonymous contributor
Published Sep 13, 2024
Contribute to Docs
In SQL, the SUBSTRING()
function takes a slice from a string containing data in binary, character, text, or image format. Upon extraction, the SELECT
statement can be used to select and manipulate the extracted substring according to the data type. The data type is the same as the original string except for the next expressions.
Syntax
SUBSTRING(string, start, length)
string
: The string to extract a substring from.start
: Thestring
index from which the substring starts. The minimum possible value is 1.length
: The number of characters to extract fromstring
.
Note: Not all services support this function. Oracle and SQLite use
SUBSTR()
to accomplish the same goal.
Example
The below example shows how to use SUBSTRING()
:
SELECT SUBSTRING('Codecademy', 1, 4) AS ExtractString;
The code above generates the following output:
ExtractString |
---|
Code |
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn SQL on Codecademy
- Skill path
Analyze Data with SQL
Learn to analyze data with SQL and prepare for technical interviews.Includes 9 CoursesWith CertificateBeginner Friendly17 hours - Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly5 hours