INITCAP
Description
The INITCAP function converts the first letter of each word in a string to uppercase and the remaining letters to lowercase. A word is defined as a sequence of alphanumeric characters separated by non-alphanumeric characters. This function is suitable for formatting names, titles, and other scenarios requiring standard case formatting.
Syntax
INITCAP(<str>)
Parameters
| Parameter | Description |
|---|---|
<str> | The string to convert case format. Type: VARCHAR |
Return Value
Returns VARCHAR type, representing the converted string.
Conversion rules:
- The first letter of each word is converted to uppercase
- Remaining letters in the word are converted to lowercase
- Words are separated by non-alphanumeric characters (spaces, punctuation, symbols, etc.)
- Numeric characters are not case-converted
- Supports Unicode character case conversion
Special cases:
- If parameter is NULL, returns NULL
- If string is empty, returns empty string
- Consecutive non-alphanumeric characters are treated as a single separator
- Letters at the beginning of the string are capitalized
Examples
- Basic word capitalization
SELECT INITCAP('hello world');
+------------------------+
| INITCAP('hello world') |
+------------------------+
| Hello World |
+------------------------+
- Mixed case conversion
SELECT INITCAP('hELLo WoRLD');
+------------------------+
| INITCAP('hELLo WoRLD') |
+------------------------+
| Hello World |
+------------------------+
- NULL value handling
SELECT INITCAP(NULL);
+---------------+
| INITCAP(NULL) |
+---------------+
| NULL |
+---------------+
- String with numbers and symbols
SELECT INITCAP('hello hello.,HELLO123HELlo');
+---------------------------------------+
| INITCAP('hello hello.,HELLO123HELlo') |
+---------------------------------------+
| Hello Hello.,Hello123hello |
+---------------------------------------+