Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If statements in WHERE clause

Tags:

oracle

Is it possible in Oracle to put conditional IF statements in the WHERE clause?

I want to filter all rows with an end date before today. And if the end date is empty, it should not filter on it. I've tried this:

SELECT discount_amount 
FROM vw_ph_discount_data 
WHERE sysdate > start_date
AND
    IF 
        end_date IS NOT EMPTY 
    THEN 
        sysdate < end_date

But I get "invalid relational operator".

like image 840
dan-klasson Avatar asked Dec 03 '22 05:12

dan-klasson


1 Answers

You can try:

SELECT discount_amount 
FROM vw_ph_discount_data 
WHERE sysdate > start_date
AND sysdate < nvl(end_date,sysdate+1)
like image 168
Florin stands with Ukraine Avatar answered Mar 03 '23 02:03

Florin stands with Ukraine