MYSQL Tutorial

MySQL LCASE() function

LCASE() function

MySQL LCASE() converts the characters of a string to lower case characters.

This function is similar to the function LOWER().


LCASE (string)


Name Description
string A string whose characters are to be converted to lowercase characters.

MySQL Version: 5.6

Video Presentation

Example of MySQL LCASE() function

The following MySQL statement converts all of the characters of the string 'MYTESTSTRING' to lower case characters and returns 'myteststring'.



Sample Output:

| myteststring          | 
1 row in set (0.00 sec)

Example of MySQL LCASE() function using where

The following MySQL statement returns those rows from the publisher table which does not contain a publisher belong to the USA. The column pub_name and pub_name in lowercase are displayed in the output.


SELECT pub_name,LCASE(pub_name) 
FROM publisher 
WHERE country<>'USA'; 

Sample table: publisher

Sample Output:

mysql> SELECT pub_name,LCASE(pub_name) 
    -> FROM publisher 
    -> WHERE country<>'USA';
| pub_name                     | LCASE(pub_name)              |
| BPP Publication              | bpp publication              | 
| New Harrold Publication      | new harrold publication      | 
| Ultra Press Inc.             | ultra press inc.             | 
| Pieterson Grp. of Publishers | pieterson grp. of publishers | 
| Novel Publisher Ltd.         | novel publisher ltd.         | 
5 rows in set (0.03 sec)

PHP script

<!doctype html>
 <html lang="en">
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>example-lcase-function - php mysql examples | w3resource</title>
 <meta name="description" content="example-lcase-function - php mysql examples | w3resource">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
 <div class="container">
 <div class="row">
 <div class="col-md-12">
 <h2>A list of Publishers those who don't belong to USA. Second column shows the name of the Publisher in lowercase:</h2>
 <table class='table table-bordered'>
 <th>Publishers name</th><th>Names in lowercase</th>
 $db = "your_dbname";
 $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
 foreach($dbh->query('SELECT pub_name,LCASE(pub_name) FROM publisher WHERE country<>"USA" ') as $row) {
 echo "<tr>";
 echo "<td>" . $row['pub_name'] . "</td>";
 echo "<td>" . $row['LCASE(pub_name)'] . "</td>";
 echo "</tr>";

View the example in browser

JSP script

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
try {
String Host = "jdbc:mysql://localhost:3306/w3resour_bookinfo";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
connection = DriverManager.getConnection(Host, "root", "datasoft123");
statement = connection.createStatement();
String Data ="SELECT pub_name,LCASE(pub_name) FROM publisher WHERE country<>'USA'";
rs = statement.executeQuery(Data);
<TABLE border="1">
<tr width="10" bgcolor="#9979">
<td>Publishers name</td>
<td>Names in lowercase</td>
while (rs.next()) {
<%   }    %>
} catch (Exception ex) {
out.println("Cant connect to database.");

MySQL: Upper case the first letter and lower case the rest of a string

We have a table called test with following records:

mysql> SELECT * FROM test;
| test_char |
| abcd      |
| WxyZ      |
| scott     |
| ROBIN     |
4 rows in set (0.00 sec)

Now we want to update the above data where the first character will be in upper case and rest will be lower case i.e. 'abcd' will be 'Abcd', 'WxyZ' will be 'Wxyz' and so on. See the following MySQL statement:

mysql> UPDATE TEST SET test_char = CONCAT(UCASE(LEFT(test_char, 1)), LCASE(SUBSTRING(test_char, 2)));
Query OK, 4 rows affected (0.04 sec)
Rows matched: 4  Changed: 4  Warnings: 0
| test_char |
| Abcd      |
| Wxyz      |
| Scott     |
| Robin     |
4 rows in set (0.00 sec)

All String Functions

MySQL String Functions, slide presentation

ankara escort
kızılay escort