Переместить условие соединения в предложение соединения.Добавляйте критерий для дат всегда.Затем проверьте, являются ли оба оставшихся параметра нулевыми или только один из них, а второй встречен.
...
from res
join pla on res.cod_ordem_producao = pla.cod_ordem_producao
where res.dth_entrada between :dth_inicio and :dth_final
and
(
(:codordemproducao is null and :grau is null)
or (
(
(:codordemproducao is null and to_char(pla.dsc_aco) = to_char(:grau))
or
(:grau is null and to_char(res.cod_ordem_producao) = to_char(:codordemproducao))
)
and res.cod_estado_tubo in ('G', 'W')
)
)
Замените :parameter is null
на to_char(:parameter) = 'X'
, если они отправлены как X
с.Как я понял ситуация, когда вы предоставляете даты и оба оставшихся параметра запрещена.