MySQL UPPER() function
UPPER() function
MySQL UPPER() converts all the characters in a string to uppercase characters.
Syntax:
UPPER (string)
Argument:
Name | Description |
---|---|
string | A string whose characters are to be converted to uppercase. |
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.
Code:
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.
Code:
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">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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">
</head>
<body>
<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'>
<tr>
<th>Publishers name</th><th>UPPER(pub_name)</th>
</tr>
<?php
$hostname="your_hostname";
$username="your_username";
$password="your_password";
$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>";
}
?>
</tbody></table>
</div>
</div>
</div>
</body>
</html>
JSP script:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>example-upper-function</title>
</head>
<body>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
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>
<td>UPPER(pub_name)</td>
</tr>
<%
while (rs.next()) {
%>
<TR>
<TD><%=rs.getString("pub_name")%></TD>
<TD><%=rs.getString("UPPER(pub_name)")%></TD>
</TR>
<% } %>
</table>
<%
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
out.println("Cant connect to database.");
}
%>
</body>
</html>
Online Practice Editor:
All String Functions
Previous: UNHEX
Next: MySQL Mathematical functions ABS()
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises