The Oracle INITCAP()
function converts the first letter of each word to uppercase and other letters to lowercase.
By definition, words are sequences of alphanumeric characters delimited by a space or any other non-alphanumeric letter.
Syntax
The following illustrates the syntax of the INITCAP()
function:
INITCAP(string)
Code language: SQL (Structured Query Language) (sql)
Arguments
The Oracle INITCAP()
function takes one argument:
1)string
is the string that should be converted to the proper case
Return value
The INITCAP()
function returns a string in the proper case or title case.
Examples
The following statement uses the INITCAP()
function to convert a string to the proper case:
SELECT
INITCAP( 'hi john' )
FROM
DUAL;
Code language: SQL (Structured Query Language) (sql)
The result is as follows:
Hi John
Code language: SQL (Structured Query Language) (sql)
We often use the INITCAP()
function to fix the data e.g., name, email, etc. that has all caps or has mixed case.
See the following contacts
table in the sample database.
The following statement selects the first name and last name from the contacts
table. In addition, it constructs the full name and converts it to the proper case using the INITCAP()
function.
SELECT
INITCAP( first_name || ' ' || last_name ) full_name
FROM
contacts
ORDER BY
full_name;
Code language: SQL (Structured Query Language) (sql)
The following picture illustrates the result.
Remarks
If you want to convert a string to uppercase, you use the UPPER()
function. In case you want to convert a string to lowercase, you use the LOWER()
function.
In this tutorial, you have learned how to use the Oracle INITCAP()
function to convert a string to a proper case.