Search code examples
sqloracle-databasespell-checkingdata-entry

How to format user input names on a large set of data from a sql/oracle database?


I have a table that stores names that are input by the user into a text edit box.

There is no selection or masking on this input box

This leads the database to have inconsistent data such as

John Doe
 John Dow
Jonh doe
johh Doe

when the name is supposed to be John Doe.

I am wondering how to create a single query that can handle parsing the names back to what they are supposed to be (i know of all the wrongly spelt name occurances) with multple user names .

Example:

select name from tableName
set
(
if(name = 'John Dow' or name = 'Johh Doe') name = 'John Doe'
)

(
if(name = 'Janee Doe' or name = 'Jaan Doe' name = 'Jane Doe'
)

Using SQL and Oracle Developer


Solution

  • Well, you can use case:

    update tableName
        set name = (case when name in ('John Dow', 'Johh Dow') then 'John Doe'
                         when name in ('Janee Doe', 'Jaan doe') then 'Jane Doe'
                         else name
                    end)
    

    You might want to include a where clause to limit the number of rows updated with the same value:

        where name in ('John Dow', 'Johh Dow', 'Janee Doe', 'Jaan doe')