How to Clean Messy Employee Names in Oracle SQL Using TRIM() and LOWER()
Have you ever worked with an employee table where names are stored in different formats?
For example, some names are in uppercase, others use mixed case, and a few have unwanted spaces around them.
Consider this sample employee data:
emp_id employee_name
101 JOHN
102 Mary
103 DAVID
104 SARAH
105 Robert
The names themselves are correct, but their formats are inconsistent.
This can become a problem when comparing records, preparing reports, or working with data from multiple sources.
Let's clean these values using Oracle SQL.
The requirement
We want to:
Remove leading and trailing spaces.
Convert all names into lowercase.
Display the cleaned values without updating the original table.
Oracle SQL query
SELECT emp_id,
LOWER(TRIM(employee_name)) AS cleaned_name
FROM employees;
Expected output:
emp_id cleaned_name
101 john
102 mary
103 david
104 sarah
105 robert
The result is now consistent across all employee…