In my project, I need to write a sql query but I have an issue.
For example, I have a thousand institutions and I need to test several fields for those institutions, but sometimes some fields don’t exist for an institution so my query discard this institution in the result.
So what I want to do, is to test if yes or not the field exist for this institution and do the condition test if yes or pass the condition if not.
Is there a way to do it simply in the ‘WHERE’ part like something like this :
where if(e.field1 exist) then e.field1='plop1' and if(e.field2 exist) then e.field2='plop2'
You can use the coalesce function for this purpose:
This will replace NULL values for the field with the String ‘plop1’, yielding a not-null result for each record.
See also http://www.techonthenet.com/oracle/functions/coalesce.php
EDIT: I’m assuming the field “field1” exists in your database schema. Otherwise, this is an entirely different problem that might have be tackled at the database / application design level.