Return the input string with the first letter of each word capitalised and every other letter lowercased.
INITCAP(str)
## Overview Returns the input string with the first letter of each word converted to uppercase and all remaining letters converted to lowercase. Word boundaries are defined as the transition from a non-alphanumeric character (whitespace, punctuation, symbols) to an alphanumeric character. INITCAP is typically used for display formatting of names, addresses, and labels that were stored in inconsistent case. INITCAP is a lossy transformation when the source contains legitimately capitalised internal letters (for example 'McDonald' becomes 'Mcdonald', 'iPhone' becomes 'Iphone'). Use it for best-effort presentation, not for preserving names of people, products, or brands exactly. ## Behavior - Returns NULL when the input is NULL. - Returns an empty string when the input is an empty string. - Word boundary is any non-alphanumeric character: spaces, tabs, newlines, hyphens, underscores, slashes, digits adjacent to letters all reset the capitalisation state. - Each word's first character is uppercased using Unicode case mapping; all other characters are lowercased. - Digits and punctuation are preserved in place. A digit does not itself receive a 'case', but a letter immediately after a digit is treated as the start of a word. - Operates on Unicode code points: multi-byte UTF-8 characters are handled correctly and the output is always valid UTF-8. - Idempotent on ASCII words without internal capitals: INITCAP(INITCAP(x)) equals INITCAP(x) for most inputs. ## Compatibility - The definition of a 'word' (alphanumeric run separated by non-alphanumerics) matches the common SQL convention. - Case mapping follows default Unicode rules. Locale-specific title-casing is not applied.
| Name | Type | Description |
|---|---|---|
str | Specifies the input string. Word boundaries are detected at the transition from a non-alphanumeric character to an alphanumeric character. |
-- Basic title case
SELECT INITCAP('hello world'); -- 'Hello World'
-- Mixed case input is normalised
SELECT INITCAP('hELLO wORLD'); -- 'Hello World'
-- Word boundaries from punctuation
SELECT INITCAP('mary-jane watson'); -- 'Mary-Jane Watson'
-- Title-case a column for display
SELECT INITCAP(LOWER(city)) AS city_display
FROM retail.customers.profiles;
-- All uppercase input is forced to title case
SELECT INITCAP('SQL FUNCTION'); -- 'Sql Function'
-- NULL propagates
SELECT INITCAP(CAST(NULL AS VARCHAR)); -- NULL