Lesson

MySQL UCASE() Function

10 min reading
Free Course

MySQL UCASE() Function

The UCASE() function converts all lowercase letters in a string to uppercase using the active character set mapping. It is a MySQL synonym for the ANSI SQL UPPER() function.

Syntax

UCASE(str)
  • str: Any non-binary character string or column expression.
  • Return value: Uppercased string, or NULL when str is NULL.

Under utf8mb4, UCASE() maps both standard ASCII letters and accented characters like 'café' into 'CAFÉ'.

Practical Example

Fulfillment exports from demo_orders require uppercase order codes and status tags so external carrier APIs parse them consistently.

SELECT
    order_id,
    order_code,
    UCASE(order_code) AS carrier_code,
    UCASE(status) AS carrier_status
FROM demo_orders
ORDER BY order_id;
order_id order_code carrier_code carrier_status
1 us-2026-881 US-2026-881 SHIPPED
2 de-2026-412 DE-2026-412 PACKED
3 fr-2026-019 FR-2026-019 NULL

Row 3 keeps carrier_status as NULL because UCASE(NULL) always evaluates to NULL without throwing a conversion error.

Common Mistakes & NULL Behavior

  • No effect on BINARY or BLOB columns: Because binary strings lack character set metadata, UCASE() returns them unchanged. Cast with CONVERT(col USING utf8mb4) before calling UCASE().
  • Full table scans in WHERE clauses: Filtering with WHERE UCASE(order_code) = 'US-2026-881' prevents MySQL from using a normal B-tree index on order_code. Rely on a case-insensitive collation or add a functional index in MySQL 8.0+.
  • Numbers and symbols stay unchanged: Digits, hyphens, and punctuation pass through as-is, and NULL inputs return NULL.

Frequently Asked Questions

Should I use UCASE() or UPPER()?

Both execute the exact same logic in MySQL. Choose UPPER() for SQL portability across PostgreSQL, SQLite, and SQL Server, or UCASE() when maintaining existing MySQL scripts.

Does UCASE() modify data stored in the table?

In a SELECT statement, it only transforms the query result. Use UPDATE demo_orders SET status = UCASE(status) to update stored values permanently.

What does UCASE('') return?

It returns an empty string ''.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
MySQL Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum