Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle -- finding values with leading or trailing spaces

Tags:

sql

oracle

I am trying to find if a certain column requires TRIM function on it.

How can I find out if this column in a table has records that have white space either before or after the actual data.

like image 836
learn_plsql Avatar asked Jul 11 '10 13:07

learn_plsql


2 Answers

You can check it using the TRIM function itself, not the most efficient but accurate:

Select *
From TableA
Where MyColumn <> TRIM(MyColumn)

Though if you're checking then turning around to trim anyway, you probably want to just do it in the first place, like this:

Select TRIM(MyColumn) as TrimmedMyColumn
From TableA
like image 52
Nick Craver Avatar answered Oct 06 '22 01:10

Nick Craver


A quick and dirty way

WHERE LENGTH(TRIM(COL1)) <> LENGTH(COL1)
like image 21
Martin Smith Avatar answered Oct 06 '22 01:10

Martin Smith