Use of substring functions.
The SUBSTRING function in SQL allows extraction of a specified portion of a string based on the user's requirements. This function is commonly used to manipulate and retrieve parts of string data from database fields.
Syntax for SUBSTRING()
SUBSTRING(Expression, Starting Position, Length)The parameters are as follows:
- Expression: The string expression from which to extract the substring.
- Starting Position: The starting index from which to begin extraction, where the first character in the string is 1.
- Length: The number of characters to extract from the string starting from the Starting Position.
CREATE TABLE team(name VARCHAR(90), address VARCHAR(50), phone_no INT, age INT);As shown in Fig. 8.1:
QUERY to Extract Substring
SELECT SUBSTRING(name, 1, 3) AS ExtractedString FROM team;
Comments
Post a Comment