Can someone help me with the below query in oracle?
The logic is that if the person has a friendlyname , use that for match with the ‘search’ criterion. Else, try to match with the realname column.
select * from people where
case when customer_friendlyname is null then realname like '%abcd%'
else
case when customer_friendlyname is not null then customer_friendlyname like '%abcd%'
end
end
Appreciated if someone could take a look.. Thank you!
In Oracle, Boolean expressions can’t be treated like other types of expressions; for example,
CASEexpressions can’t evaluate to them. So you need to rewrite this.In this case, since you have the same
LIKE '%abcd%'predicate in both branches, you could just factor it out:but it’s simpler to make use of the built-in
NVLfunction, and write: