Menu

How to Clean Messy Employee Names in Oracle SQL Using TRIM() and LOWER()
📰

How to Clean Messy Employee Names in Oracle SQL Using TRIM() and LOWER()

DEV Community: database·Kailas Warade·10 days ago
#7viTDgXc
#devtodatabase#devto#dev#john#trim
Reading 0:00
15s threshold

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…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.