SQL UPPER function
Returns the string with every character uppercased. Non-ASCII letters follow the collation's case rules, and uppercasing a column in a WHERE clause stops a plain index on it from being used.
- 类别
- Strings
- Returns
string- In this category
- 4 of 172
语法
UPPER(string)
引擎支持
| 引擎 | Support | 备注 |
|---|---|---|
| SQL Server | 是 | Supported under this name. |
| PostgreSQL | 是 | Supported under this name. |
| MySQL | 是 | Supported under this name. |
| SQLite | 是 | Supported under this name. |
| Oracle | 是 | Supported under this name. |
示例
Any engine
SELECT UPPER('mixed Case') AS shouted; -- MIXED CASE
PostgreSQL
CREATE INDEX users_email_upper_idx ON users (UPPER(email));
值得了解
- UPPER maps one character to one character on all five engines by default, so UPPER('straße') stays 'STRAßE'. PostgreSQL 18's pg_unicode_fast collation applies full Unicode case mapping and returns 'STRASSE'.
- SQLite's built-in UPPER only changes ASCII letters: UPPER('é') stays 'é' unless the ICU extension is loaded.
- WHERE UPPER(email) = ... cannot use a plain index on email. Use a case-insensitive collation or an expression index. PostgreSQL's ILIKE does not help here: it cannot use a plain b-tree index either.
Questions about UPPER
Why does UPPER make my query slow?
Wrapping a column in a function stops the plain index on that column from being used. Add an expression index on UPPER(column), or compare case-insensitively via collation instead.
Do I need UPPER for case-insensitive matching?
On SQL Server and MySQL, usually not: their default collations are case-insensitive, so 'a' = 'A' is already true. PostgreSQL, Oracle and SQLite compare case-sensitively with =, so LOWER/UPPER on both sides, ILIKE (PostgreSQL) or a case-insensitive collation is needed. SQLite's LIKE is case-insensitive for ASCII only.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
- Find auto-increment and identity columns Snippet
- Capitalize only the first letter of a value in SQL Snippet
- Title-case names in SQL (INITCAP and friends) Snippet
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.