SQL NLS_UPPER / NLS_LOWER function
Upper- and lowercase a string under named linguistic rules, for the cases where plain UPPER('i') answers the wrong language.
- 类别
- Strings
- Returns
string- In this category
- 27 of 172
语法
NLS_UPPER(string [, 'NLS_SORT=sort'])
lower(string COLLATE "collation")
Each block is a separate form. The support table and the examples show which engine takes which.
引擎支持
| 引擎 | Support | 备注 |
|---|---|---|
| SQL Server | Not built in | No built-in equivalent. |
| PostgreSQL | 是 | plain upper()/lower() with a COLLATE clause; ICU collations from PG 10 |
| MySQL | Not built in | No built-in equivalent. |
| SQLite | Not built in | No built-in equivalent. |
| Oracle | 是 | Supported under this name. |
示例
Oracle
SELECT NLS_UPPER('straße', 'NLS_SORT=XGerman') AS de, UPPER('straße') AS plain FROM dual;
-- STRASSE, STRAßE
PostgreSQL
SELECT lower('I' COLLATE "tr-TR-x-icu") AS tr; -- ı
值得了解
- Plain UPPER in Oracle leaves ß alone: UPPER('straße') is STRAßE, while NLS_UPPER('straße', 'NLS_SORT=XGerman') expands it to STRASSE.
- PostgreSQL has no extra function: lower('I' COLLATE "tr-TR-x-icu") gives the dotless ı, while plain lower('I') gives i under most database locales.
- MySQL's UPPER/LOWER follow the argument's collation casing tables but expose no per-call locale override.
- SQL Server picks casing per column/expression collation: UPPER('i' COLLATE Turkish_CI_AS); no separate function.
Questions about NLS_UPPER / NLS_LOWER
When do I need NLS_UPPER instead of UPPER?
When the data is in a language whose casing has extra rules: Turkish dotted I, German sharp s. Plain UPPER applies one mapping for every language.
What is the PostgreSQL equivalent?
An expression COLLATE on the ordinary functions: lower('I' COLLATE "tr-TR-x-icu"). PostgreSQL has no two-argument lower(); the collation carries the locale.
Does this affect WHERE comparisons too?
Casing in comparisons comes from the collation, not these functions; a case-insensitive collation can make the functions unnecessary for matching.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: PostgreSQL, 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.