MYSQL Tutorial

MySQL UPPER() function

UPPER() function

MySQL UPPER() converts all the characters in a string to uppercase characters.


UPPER (string)


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

Syntax Diagram:

MySQL UPPER() Function - Syntax Diagram

MySQL Version: 5.6

Your browser does not support HTML5 video.

Example : MySQL UPPER() function

The following MySQL statement returns the given string after converting all of its characters in uppercase.


SELECT UPPER('myteststring');

Sample Output:

mysql> SELECT UPPER('myteststring');
| UPPER('myteststring') |
| MYTESTSTRING          | 
1 row in set (0.00 sec)

Example of MySQL UPPER() function with where clause

The following MySQL statement returns those rows from the publisher table whose publishers are not belonging the country USA. The column pub_name, and values of publisher names in uppercase have been shown in the output.


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

Sample table: publisher

Sample Output:

mysql> SELECT pub_name,UPPER(pub_name) 
    -> FROM publisher 
    -> WHERE country<>'USA';
| pub_name                     | UPPER(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.11 sec)

PHP script

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>example-upper-function - php mysql examples | w3resource</title>
<meta name="description" content="example-upper-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 belong to USA. Second column shows name of the Publisher in upper case:</h2>
<table class='table table-bordered'>
<th>Publishers name</th><th>UPPER(pub_name)</th>
$db = "your_dbname";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT pub_name,UPPER(pub_name) 
FROM publisher 
WHERE country<>"USA"') as $row) {
echo "<tr>";
echo "<td>" . $row['pub_name'] . "</td>";
echo "<td>" . $row['UPPER(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,UPPER(pub_name) FROM publisher WHERE country<>'USA'";
rs = statement.executeQuery(Data);
<TABLE border="1">
<tr width="10" bgcolor="#9979">
<td>Publishers name</td>
while (rs.next()) {
<%   }    %>
} catch (Exception ex) {
out.println("Cant connect to database.");

All String Functions

MySQL String Functions, slide presentation

Many of our valued users post comments along with piece of code. Disqus may, false positively, consider those piece of code as Bad or Starnge syntax and send those comments to spam automatically. Even if that happens, we will make sure those useful comments are taken out of spam and approved. It may take a couple of days for that though, but any useful comment will be brought to public view for sure. We regret if that happend to any user. You may write us directly regarding this to - w3resource[at]yahoo[dot]com.