-1
Good afternoon ! I have a task to perform a select, but the parameters are passed as variables and I need to treat the input of one of these variables with the following logic: if &CT is not null, then I add in the condition of select the values that were suggested in this variable, if it is null, then I do not want to perform this condition in the select filter. I am working with PL/SQL Oracle.
select * from TABELA t
WHERE TRUNC(T.DATASTAMP) BETWEEN '&DATA_INICIAL' AND '&DATA_FINAL'
AND ( CASE WHEN &CT IS NOT NULL THEN T.CENTRO_TRABALHO = &CT END );
this way is giving error, both putting value in the variable and leaving it null.
can’t be done like this, the
case when
should return a value, based on several cases, and compare with something at the end, for example:where campo = (case campo2=1 then 10 else 20 end)
, will always compare "field" to a value that depends on "field2"– Ricardo Pontual