INITCAP()

SQL · String Functions

Theory

INITCAP(string) converts a string to 'title case': the first letter of each word becomes uppercase and the rest of the word becomes lowercase. INITCAP('asha rao') and INITCAP('ASHA RAO') both return 'Asha Rao'. A word is any run of letters and digits, so anything else (space, hyphen, apostrophe) starts a new word.

INITCAP exists in Postgres, Oracle and Snowflake, but not in MySQL, SQL Server or SQLite. There you emulate it. For a single word, UPPER(SUBSTR(name, 1, 1)) || LOWER(SUBSTR(name, 2)) works; for two words you also find the space with INSTR and treat the second word the same way, as the diagram does. Be aware that simple title-casing is not perfect for every name: 'McDonald' becomes 'Mcdonald' and "o'brien" becomes "O'Brien". For display, that is usually good enough.

Why we use it

Names and cities often arrive in random case from forms and files: 'RAVI KUMAR', 'meera joshi'. INITCAP gives them a clean, consistent look for reports, labels and emails without changing them by hand.

When to use it

Use INITCAP for display formatting of names, cities and titles. Do not use it to compare values (use LOWER or UPPER for that). In dialects without INITCAP, emulate with SUBSTR plus UPPER/LOWER, or format in the application layer.

How it works

  1. Take the input string
  2. Read the next character
  3. Is it the first letter of a word? Yes: Make it uppercase. No: Make it lowercase.
  4. A non-letter (space, hyphen) marks the start of a new word
  5. Return the title-cased string

Syntax

INITCAP(string)

Example

SELECT INITCAP('asha rao');
-- 'Asha Rao'

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic