Domanda

Hi i have a form in my java app to do advanced research. there are several fields in there and the user can fill the one he wants, so in order to do my search in he database i am was thniking of something like this.

SELECT DISTINCT F.ID_FILM, F.langue FROM FILM F , PAYS PA, FILM_PAYS FPA,
WHERE F.TITRE LIKE '%%'
AND (F.LANGUE IS NULL OR upper(F.LANGUE)  LIKE upper('%%'))
AND F.ANNEE LIKE '%%'
AND F.DUREE BETWEEN 0 AND 1000
AND F.SYNOPSIS LIKE '%%'
AND (PA.NOM_PAYS LIKE '%%' AND PA.ID_PAYS = FPA.ID_PAYS AND FPA.ID_FILM = F.ID_FILM)

I will replace %% by %?% in java for my prepared stattement, so if field is empty i will replace ? by "", the problem is that LIKE %% will return everything bare null values, and the OR i am inserting will make make the query always return the empty LANGUE films in addtion to the one matching the pattern.

È stato utile?

Soluzione

If you want to handle NULLS, you could use the NVL function as below:

WHERE NVL(F.TITRE, 'NULL') LIKE '%%'

and so on for other columns.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top