Ad space (banner)
🗄️SQL Lessons
Lesson 46 / 50

String Functions: UPPER, LENGTH, and SUBSTR

This lesson covers string functions — UPPER, LENGTH, and SUBSTR — so you can clean up inconsistent text data. It's for anyone searching "SQL string functions tutorial."

SQL also has functions for manipulating text: UPPER(column) converts to uppercase, LENGTH(column) gets the character count, and SUBSTR(column, start, length) extracts part of a string.

The example applies UPPER(), LENGTH(), and SUBSTR(code, 1, 3) to a product code, all as separate columns in the same result — a good look at combining several string functions in one SELECT.

A common early mistake is miscounting the starting position for SUBSTR() — SQL's string functions typically count the first character as position 1, so if you're used to 0-based indexing from another language, results tend to land one character off from what you expect. Extracting the first few characters of a product code, or normalizing case before comparing values, are the kind of text-cleanup tasks this handles well — and the feel is quite similar to string handling in general-purpose programming languages once you get used to it.

SQL
OUTPUT

💡 The SQL engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)