문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top