Problem:
In a PostgreSQL string, you need to make the first letter of each word uppercase and the rest of the letters lowercase.
Example:
Our database has a table named student
with data in two columns, id
and full_name
.
id | full_name |
1 | ANNE WILLIAMS |
2 | alice brown |
3 | Gary JACKSON |
Let’s change the capitalization of students’ full names by converting this string so that only the first letters of the first and last names are capitalized – just as we’d normally write them.
Solution:
We’ll use the INITCAP()
function. Here’s the query you’d write:
SELECT INITCAP (full_name) AS new_full_nameFROM student;
Here’s the result:
new_full_name |
Anne Williams |
Alice Brown |
Gary Jackson |
Discussion:
In PostgreSQL, you can use the INITCAP()
function to convert a string to a new string that capitalizes the first letter of every word. All other letters will be lowercase. This function takes one parameter as a string and changes the capitalization for each word as described.
In our example, the full name Anne Williams was originally stored in the column full_name
as ANNE WILLIAMS
; after converting, this full name is Anne Williams
.
FAQs
In PostgreSQL, you can use the INITCAP() function to convert a string to a new string that capitalizes the first letter of every word. All other letters will be lowercase. This function takes one parameter as a string and changes the capitalization for each word as described.
How do you capitalize the first letter of each word in SQL? ›
The UCASE function is used to convert the first letter of each word to uppercase, and LCASE is used to convert the rest of the word to lowercase. This is then concatenated together using the CONCAT function.
How do you capitalize the first letter of each word? ›
To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and then press fn+ SHIFT + F3 until the style you want is applied.
How do you uppercase the first letter of each word in MySQL? ›
You can use the UCWORDS() function in MySQL to capitalize the first letter of each word in a column. Here is an example query that demonstrates how to use this function: UPDATE your_table SET your_column = UCWORDS(your_column);
How do you capitalize the first letter of each word in sheets? ›
The Proper Function
The syntax =PROPER(text) requires either a direct string of text or a cell reference as its argument. Effectively, it capitalizes the first letter of every word in a given string, making it useful for formatting titles or headings in your spreadsheet.
How do you capitalize the first letter in PostgreSQL? ›
In PostgreSQL, you can use the INITCAP() function to convert a string to a new string that capitalizes the first letter of every word. All other letters will be lowercase.
How do you capitalize keywords in SQL? ›
No, SQL is not a case-sensitive language, so it doesn't matter if you use upper case or lower case for SQL commands. However, it's recommended to use a consistent capitalization style for better code readability and maintainability.
Which function will you use to capitalize first letter of each word? ›
Method 1: Using charAt(), toUpperCase(), and slice()
Explanation: This function takes a string as an argument and capitalizes its first letter. It does this by using charAt(0) to access the first character of the string and toUpperCase() to convert this character to uppercase.
Can you capitalize the first letter? ›
This is a stable rule in our written language: Whenever you begin a sentence capitalize the first letter of the first word. This includes capitalizing the first word or a direct quotation when it's a full sentence, even if it appears within another sentence. Her daughter loved the valentine.
When you capitalize the first letter of each word with no spaces? ›
Camel case (sometimes stylized autologically as camelCase or CamelCase, also known as camel caps or more formally as medial capitals) is the practice of writing phrases without spaces or punctuation and with capitalized words.
INITCAP returns char , with the first letter of each word in uppercase, all other letters in lowercase. Words are delimited by white space or characters that are not alphanumeric.
How do you get the first character of each word in a string in SQL? ›
we sometimes categorize the data based on the first character of the string. To get the first character from a string, we can use the SUBSTRING() function or SUBSTR() function.
How do you check if the first letter of a string is uppercase? ›
We'll need to use the isUpperCase method from the Ascii class to check if the first letter of a string is uppercase. Then, we'll apply the isUpperCase method to the first letter of our example string: Assertions. assertTrue(Ascii.
How do you capitalize the first letter of each word in a string in CSS? ›
You can use the text-transform CSS property to capitalize text in different forms. This property can modify text to be in uppercase, lowercase, or capitalized (so that each word begins with a capital letter and the remaining characters in the word retain their original form).
Is there a way to capitalize the first letter of every word in Excel? ›
Step 1: Type the individual names in Excel. Step 2: The cell to the right of the first name, type in the formula. Example: =PROPER(A2) Step 3: Use the fill handle to copy the formula to the other cells in the spreadsheet. Hint: Make sure all formulas/functions in Excel start with an equals sign.
How do you capital letters in SQL? ›
If you wanted to convert the name column to uppercase, you would use the following query: SELECT UPPER(name) FROM users; This query would return the result JOHN, JANE, JOHN, BOB, since all of the names in the table have been converted to uppercase.
What is the shortcut for capitalize all letters in SQL? ›
- Upper Case : ctr + shift + U.
- Lower Case : ctr + shift + L.