Introduction
We use SUBSTRING extraction to get a smaller part of a text from a bigger text. It helps us focus on just the piece we need.
SUBSTRING(string_expression FROM start_position FOR length)SELECT SUBSTRING('Hello World' FROM 1 FOR 5);
SELECT SUBSTRING('abcdef' FROM 3 FOR 2);
SELECT SUBSTRING('Short' FROM 2 FOR 10);
SELECT SUBSTRING('Example' FROM 8 FOR 3);
CREATE TABLE Products (ProductID INT, ProductCode VARCHAR(20)); INSERT INTO Products VALUES (1, 'ABC123XYZ'), (2, 'DEF456'), (3, 'GHI7890'); SELECT ProductID, ProductCode, SUBSTRING(ProductCode FROM 1 FOR 3) AS CodePrefix FROM Products;
SUBSTRING('Hello World', 7, 5) return?Users with a column username containing 'john_doe123', what is the result of SELECT SUBSTRING(username, 6, 4) FROM Users;?SELECT SUBSTRING('Database', 0, 4);product_code with values like 'AB12345XYZ'. Write a SQL query to extract the numeric part (5 digits) starting from position 3. Which query correctly extracts '12345'?Pass the test and this pattern moves unknown