Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using trim on empty string in where clause in ORACLE SQL

Tags:

sql

oracle

I'm trying to figure out why the below SQL statement does not return the value do in oracle

Select 'do' from dual
where trim('  ') = ''

Where as

Select 'do' from dual
where trim(' a ')='a'

returns the value do.

like image 445
nJoshi Avatar asked Oct 30 '12 00:10

nJoshi


1 Answers

because trim(' ') returns null and not ''

SQLFiddle example

In Oracle 8, there is no such thing as a zero-length string. Any zero-length string, either from a function call or the literal '', is treated as null.

Source

like image 126
juergen d Avatar answered Sep 20 '22 13:09

juergen d