Oracle INITCAP Function: A Simple Guide to Capitalizing Words

When you have text data in your Oracle database that is messy—like all lowercase or all uppercase—it can look unprofessional in reports. The INITCAP function is a simple and powerful tool to fix this.

This guide will explain what the Oracle INITCAP function is, its syntax, and how to use it with practical examples to clean up your data.

What is the INITCAP Function in Oracle?

The INITCAP function (which stands for "Initial Capitalization") converts a string into "title case."

It works by following two simple rules:

  1. It makes the first letter of every word uppercase.
  2. It makes all other letters lowercase.

Oracle considers a "word" to be any set of letters separated by a space or any character that isn't a letter or number (like a hyphen -, a period ., or a comma ,).

INITCAP Function Syntax

The syntax for the INITCAP function is very simple:

INITCAP(char)

Let's break that down:

  • char: This is the string or column name you want to format. It can be a CHAR, VARCHAR2, NCHAR, or NVARCHAR2 data type.

Oracle INITCAP Function Examples

Here are two practical examples of how to use INITCAP in your Oracle SQL queries.

Example 1: Cleaning Up a Messy String with INITCAP

This is the most direct way to use INITCAP. Imagine you have a string that is a mix of all caps and all lowercase. INITCAP will clean it up perfectly into title case.

We use the DUAL table for this test, which is a special one-row, one-column table in Oracle.

Query:

SELECT
  INITCAP('the quick BROWN fox JUMPS over the LAZY dog') AS Cleaned_String
FROM DUAL;

Result:

CLEANED_STRING
---------------------------------------------
The Quick Brown Fox Jumps Over The Lazy Dog

Notice how it corrected both BROWN (uppercase) and the (lowercase) automatically.

Example 2: Using INITCAP Formatting Data from a Table Column

A more common use is to clean up data stored in a table. Imagine you have a products table with a product_name column that has inconsistent capitalization.

Let's use UNION ALL to simulate a table with messy data:

Query:

-- This query mimics a table with two messy product names
-- and shows how INITCAP cleans them up.
SELECT 
  'apple iPHONE 15 PRO' AS original_name,
  INITCAP('apple iPHONE 15 PRO') AS clean_name
FROM DUAL
UNION ALL
SELECT 
  'SAMSUNG galaxy BOOK 4', 
  INITCAP('SAMSUNG galaxy BOOK 4')
FROM DUAL;

Result:

ORIGINAL_NAME            CLEAN_NAME
------------------------ ------------------------
apple iPHONE 15 PRO      Apple Iphone 15 Pro
SAMSUNG galaxy BOOK 4    Samsung Galaxy Book 4

As you can see, this is perfect for making data from a column look consistent and professional for reports and applications.

Vinish Kapoor
Vinish Kapoor

Vinish Kapoor is a seasoned software development professional and a fervent enthusiast of artificial intelligence (AI). His impressive career spans over 25+ years, marked by a relentless pursuit of innovation and excellence in the field of information technology. As an Oracle ACE, Vinish has distinguished himself as a leading expert in Oracle technologies, a title awarded to individuals who have demonstrated their deep commitment, leadership, and expertise in the Oracle community.

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments