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 execute this condition on the select filter. I'm working with Oracle PL / SQL.
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 it is giving error, both putting value in the variable and leaving it null.