Wednesday, October 14, 2015

Using Case in WHERE clause

Dynamic Conditional Where Clause in SQL

SELECT < col1 > , < col2 >
FROM < table >
WHERE col1 like DECODE(:Param_one,'ALL','%',:Param_one) or
    NVL(col2,'#') = case
        when :Param_one = 'ALL' then
            '#'
        else
            col2
        end

No comments: