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.
INITCAP(<str>)
| Parameter | Description |
|---|---|
<str> | The string to convert case format. Type: VARCHAR |
Returns VARCHAR type, representing the converted string.
Conversion rules:
Special cases:
SELECT INITCAP('hello world');
+------------------------+ | INITCAP('hello world') | +------------------------+ | Hello World | +------------------------+
SELECT INITCAP('hELLo WoRLD');
+------------------------+ | INITCAP('hELLo WoRLD') | +------------------------+ | Hello World | +------------------------+
SELECT INITCAP(NULL);
+---------------+ | INITCAP(NULL) | +---------------+ | NULL | +---------------+
SELECT INITCAP('hello hello.,HELLO123HELlo');
+---------------------------------------+ | INITCAP('hello hello.,HELLO123HELlo') | +---------------------------------------+ | Hello Hello.,Hello123hello | +---------------------------------------+
SELECT INITCAP('');
+-------------+ | INITCAP('') | +-------------+ | | +-------------+
SELECT INITCAP('word1@word2#word3$word4');
+------------------------------------+ | INITCAP('word1@word2#word3$word4') | +------------------------------------+ | Word1@Word2#Word3$Word4 | +------------------------------------+
SELECT INITCAP('ṭṛì ḍḍumai hello');
+--------------------------------------+ | INITCAP('ṭṛì ḍḍumai hello') | +--------------------------------------+ | Ṭṛì Ḍḍumai Hello | +--------------------------------------+
SELECT INITCAP('john doe'), INITCAP('MARY JANE');
+---------------------+----------------------+ | INITCAP('john doe') | INITCAP('MARY JANE') | +---------------------+----------------------+ | John Doe | Mary Jane | +---------------------+----------------------+
SELECT INITCAP('the quick brown fox'), INITCAP('DATABASE management SYSTEM');
+--------------------------------+---------------------------------------+ | INITCAP('the quick brown fox') | INITCAP('DATABASE management SYSTEM') | +--------------------------------+---------------------------------------+ | The Quick Brown Fox | Database Management System | +--------------------------------+---------------------------------------+
SELECT INITCAP('word1 word2--word3'), INITCAP('hello, world! how are you?');
+---------------------------------+---------------------------------------+ | INITCAP('word1 word2--word3') | INITCAP('hello, world! how are you?') | +---------------------------------+---------------------------------------+ | Word1 Word2--Word3 | Hello, World! How Are You? | +---------------------------------+---------------------------------------+