UPPER()
SQL · String Functions
Theory
UPPER(string) returns the string with every letter converted to uppercase, leaving digits, spaces and symbols as they are. UPPER('jaipur') returns 'JAIPUR'. Like LOWER, it does not change stored data unless used in an UPDATE.
It is used to normalise codes and labels that are expected in capitals: department codes, country and state codes, PAN-style IDs, product SKUs. If the same department is stored as 'it', 'IT' and 'It', a GROUP BY dept treats them as three different groups in case-sensitive databases, while GROUP BY UPPER(dept) brings them together, as the diagram shows. UPPER is also used for case-insensitive comparison (UPPER(a) = UPPER(b)). It handles accented and other alphabets according to the database's character rules, so results for non-English text can vary slightly between systems.
Why we use it
Inconsistent capitalisation splits what should be one group into several and breaks lookups against code tables. UPPER gives every value one canonical form so grouping, joining and display are consistent.
When to use it
Use UPPER for codes and labels that should be all caps, or to normalise both sides of a comparison. For proper names that need 'Asha Rao' style, use INITCAP (where available). Fix the data at load time when you can, rather than in every query.
How it works
- Take the input string
- Read each character
- Is it a lowercase letter? Yes: Replace it with its uppercase form. No: Keep it unchanged.
- Repeat to the end of the string
- Return the uppercased copy
Syntax
UPPER(string)Example
SELECT UPPER(department) FROM employees;Key points
- Common for normalising codes and labels
- Opposite of LOWER()
- GROUP BY UPPER(col) merges groups that differ only in case
- Digits and symbols are unchanged
- Better to clean case once at load time than in every query