How to use the INICAP() function in SQL

The SQL INITCAP() function

The INITCAP() function converts the first character of each string to upper case and the remaining characters to lower case.

Syntax

INITCAP(string)

Parameter

  • string: This represents the string to be altered.

Example

The following code shows how to use the INITCAP() function in SQL:

CREATE TABLE Product (
id int,
product_name varchar(50),
price varchar(50),
product_id varchar (20)
);
-- Insert data
INSERT INTO Product
VALUES (101,'t-shirt','$100','boo-01-345');
INSERT INTO Product
VALUES (102,'hand Bag','$65','boo-01-238');
INSERT INTO Product
VALUES (103,'ipad','$1200','boo-01-103');
INSERT INTO Product
VALUES (104,'cereal','$30','boo-01-775');
INSERT INTO Product
VALUES (105,'microwave','$520','boo-01-788');
INSERT INTO Product
VALUES (106,'cloth clips','$15','boo-01-924');
INSERT INTO Product
VALUES (108,'zara Perfume','$120','boo-01-245');
-- Query
SELECT id, product_name, INITCAP(product_name) AS new_product_name
FROM Product;

Explanation

  • Lines 1–6: We create a table called Product that has the id, product_name, price, and book_id columns.
  • Lines 9–22: We insert data into the table.
  • Lines 25–26: We retrieve the data in the id, and product_name columns. We then use the INITCAP() function to alter the first character of each product name to uppercase and store it in a new column, new_product_name.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources