Selecting & Updating First Character of the First Word in Upper Case in MySQL

0

Unlike PHP and ASP which has the inbuilt function to convert the first character of the first word in the upper case of a given string type, MySQL lacks this feature though you can have your own inbuilt custom code to do so. See below two examples on how to select and update the first character of the first word in the upper case in MySQL command-line as well as in phpMyAdmin.

How to Select First Character of First Word to Upper Case in MySQL?

MySQL command-line as well as phpMyAdmin does not offer the facility to select the first character of the first letter to the upper case. Using below to customize MySQL  Query you can select the first character of the first letter to the upper case —

select concat(upper(left(column_name,1)),substring(column_name,2)) from table_name;

How to Update First Character of First Word to Upper Case in MySQL?

It is very easy to update the records once you have run the above snippet successfully. All you need to change the parameter of the query to update your records. You can use the following MySQL query to update your records with the changes.

update table_name set column_name=concat(upper(left(column_name,1)),substring(column_name,2));

Capitalizing with PHP and MySQL?

PHP has the inbuilt function to capitalize the first character of the first letter using the function ucfirst. See below for an example: –

$sql = "SELECT name FROM students";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo ucfirst($row["name"]);
    }
} else {
    echo "0 results";
}

Comments

Loading...