Db2 INITCAP

Summary: in this tutorial, you will learn how to use the INITCAP() function to convert a string to proper case.

Db2 INITCAP() function overview

The INITCAP() function converts the first character in each word in a string to uppercase and converts other characters in each word to lowercase. In other words, the INITCAP() function converts a string to a title case or proper case.

The following illustrates the syntax of the INITCAP() function:

INITCAP(string)
Code language: SQL (Structured Query Language) (sql)

In this syntax, you specify the string that you want to convert to title case.

Db2 INITCAP() function examples

Let’s take some examples of using the INITCAP() function.

1) Using Db2 INITCAP() function to convert a literal string to title case

This example uses the INITCAP() function to convert the string ‘this is a test’ to title case:

SELECT INITCAP('this is a test') FROM SYSIBM.SYSDUMMY1;
Code language: SQL (Structured Query Language) (sql)

Here is the output:

RESULT -------------- This Is A Test
Code language: SQL (Structured Query Language) (sql)

2) Using Db2 INITCAP() function with table data example

This example uses the INITCAP() function to convert the book title from the books table in the sample database to title case:

SELECT INITCAP(title) FROM books ORDER BY title;
Code language: SQL (Structured Query Language) (sql)

The output is as follows:

db2 initcap function example

In this tutorial, you have learned how to use the Db2 INITCAP() function to convert a string to title case.

Was this tutorial helpful ?