In Oracle, the INITCAP()
function returns its argument with the first letter of each word in uppercase, and all other letters in lowercase.
For special linguistic requirements for case conversions, you may want to try the NLS_INITCAP()
function instead.
Syntax
The syntax goes like this:
INITCAP(char)
Where char
can be of any of the data types CHAR
, VARCHAR2
, NCHAR
, or NVARCHAR2
.
Example
Here’s a simple example to demonstrate:
SELECT INITCAP('ponzi investment house')
FROM DUAL;
Result:
INITCAP('PONZIINVESTMENTHOUSE') __________________________________ Ponzi Investment House
What if I Pass All UPPERCASE Letters?
Passing all uppercase letters doesn’t change the result:
SELECT INITCAP('PONZI INVESTMENT HOUSE')
FROM DUAL;
Result:
INITCAP('PONZIINVESTMENTHOUSE') __________________________________ Ponzi Investment House
Null Values
Passing null
returns null
:
SET NULL 'null';
SELECT INITCAP(null)
FROM DUAL;
Result:
INITCAP(NULL) ________________ null
By default, SQLcl and SQL*Plus return a blank space whenever null
occurs as a result of a SQL SELECT
statement.
However, you can use SET NULL
to specify a different string to be returned. Here I specified that the string null
should be returned.
Incorrect Argument Count
Calling INITCAP()
without passing any arguments returns an error:
SELECT INITCAP()
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT INITCAP() FROM DUAL Error at Command Line : 1 Column : 8 Error report - SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments" *Cause: *Action:
And passing the wrong number of arguments results in an error:
SELECT INITCAP('Gosh', 'Dang', 'Investments')
FROM DUAL;
Result:
Error starting at line : 1 in command - SELECT INITCAP('Gosh', 'Dang', 'Investments') FROM DUAL Error at Command Line : 1 Column : 8 Error report - SQL Error: ORA-00909: invalid number of arguments 00909. 00000 - "invalid number of arguments" *Cause: *Action: