Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a 'Proper case' formatting of a mysql column?

Tags:

mysql

Is it possible in mysql to format a column in Proper Case?

Example: Proper("ABSALOM") = "Absalom"

I have searched a lot and I think MySQL doesn't have any inbuilt function to do this. Is it possible to do this any other way in MySQL?

like image 212
Shyam Natraj Kanagasabapathy Avatar asked May 31 '11 00:05

Shyam Natraj Kanagasabapathy


People also ask

How do you get a proper case in SQL?

NOTE you would have to use this as you would have to use it as.... SELECT dbo. ProperCase(LOWER(column)) since the column is in uppercase.

How do I make the first letter capital in MySQL?

Actually, there is no single function in MySQL to capitalize only first letter of the string. We need to use nesting of functions and for this case, we can use UPPER() and LOWER() with SUBSTRING() functions.


1 Answers

You can combine CONCAT and SUBSTRING:

CONCAT(UCASE(SUBSTRING(`fieldName`, 1, 1)), LOWER(SUBSTRING(`fieldName`, 2))) 
like image 162
Dave Maple Avatar answered Sep 22 '22 14:09

Dave Maple