SQL - String Functions

Overview

String functions manipulate text. Not all functions are identical across engines, but core capabilities exist.

SELECT UPPER('abc'), LOWER('ABC'), LENGTH('Hello'), TRIM('  hi  ');
SELECT SUBSTRING('abcdef', 2, 3);
SELECT UPPER('abc'), LOWER('ABC'), LEN('Hello'), LTRIM(RTRIM('  hi  '));
SELECT SUBSTRING('abcdef', 2, 3);
SELECT UPPER('abc'), LOWER('ABC'), LENGTH('Hello'), TRIM('  hi  ');
SELECT SUBSTR('abcdef', 2, 3);

Prerequisite

Load the Standard Test Data.

Live Examples (SQLite)

upperclowerclentrimmed
ABCabc5hi
substr
bcd

Use case: normalize employee names (view)

idupper_name
1ADA
2BOB
3CHEN
4DEE
5ELI