🔤 String Functions in SQL
Last Updated: Jan 2026
It Help To Work With Text Data In SQL.
Most Common String Functions
LENGTH()
- Returns the number of characters in a string.
SELECT LENGTH('Hello World');
UPPER()
- Converts a string to uppercase.
SELECT UPPER('hello world');
LOWER()
- Converts a string to lowercase.
SELECT LOWER('HELLO WORLD');
CONCAT()
- Concatenates two or more strings into a single string.
SELECT CONCAT('Hello', ' ', 'World');
SUBSTRING()
- Extracts a substring from a string.
/*
SUBSTRING(string, start, end)
*/
SELECT SUBSTRING('Hello World', 1, 5);
-- Output: Hello
LEFT()
- Returns the leftmost characters of a string.
/*
LEFT(string, no_of_characters)
*/
SELECT LEFT('Hello World', 5);
-- Output: Hello
RIGHT()
- Returns the rightmost characters of a string.
/*
RIGHT(string, no_of_characters)
*/
SELECT RIGHT('Hello World', 5);
-- Output: World
REPLACE()
- Replaces a substring in a string with another substring.
/*
REPLACE(string, old_substring, new_substring)
*/
SELECT REPLACE('Hello World', 'World', 'Universe');
-- Output: Hello Universe
INSTR()
- Returns the position of the first occurrence of a substring in a string.
/*
INSTR(string, substring)
*/
SELECT INSTR('Hello World', 'World');
-- Output: 6
Trim()
- Removes leading and trailing spaces from a string.
/*
TRIM(string)
*/
SELECT TRIM(' Hello World ');
-- Output: Hello World
CONCAT_WS()
- Concatenates multiple strings with a separator.
/*
CONCAT_WS(separator, string1, string2, ...)
*/
SELECT CONCAT_WS(' ', 'Hello', 'World');
-- Output: Hello World
LPAD()
- Adds padding to the left of a string.
/*
LPAD(string, total_length, padding_character)
*/
SELECT LPAD('Hello', 10, '*');
-- Output: ***Hello
RPAD()
- Adds padding to the right of a string.
/*
RPAD(string, total_length, padding_character)
*/
SELECT RPAD('Hello', 10, '*');
-- Output: Hello***