Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i get this CASE statement right in PLSQL?

I’m getting ORA- 00936 missing expression error near > symbol while trying to run this request :

SELECT contract_ref_no,
       component
FROM   some_table
WHERE  Contract_ref_no = '123'
AND    component = 'ABC'
AND end_date
   (CASE WHEN NVL(l_neg_esn_allowed,'N') = 'N' 
    THEN 
       > greatest(nvl(l_conv_eff_date, l_contract_vdate),
                l_contract_vdate)
    ELSE                 
       >=
     greatest(nvl(l_conv_eff_date, l_contract_vdate),
                         l_contract_vdate)  
    END) 

How can I fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

With a bit reformulation based on the rules of Aristoteles you may write

  • you allways want the end_date is greather than your greatest expression

OR

  • in the else case NVL(l_neg_esn_allowed,'N') != 'N' thay may be equal

Predicate

AND (
end_date  >  greatest(nvl(l_conv_eff_date, l_contract_vdate), l_contract_vdate)
OR
NVL(l_neg_esn_allowed,'N') != 'N'  and  end_date = greatest(nvl(l_conv_eff_date, l_contract_vdate), l_contract_vdate)
)

which is the same as the predicate below that more resembles your original intention

....
AND (
NVL(l_neg_esn_allowed,'N') = 'N' AND end_date > greatest(nvl(l_conv_eff_date, l_contract_vdate),l_contract_vdate)
OR
NVL(l_neg_esn_allowed,'N') != 'N' AND end_date >= greatest(nvl(l_conv_eff_date, l_contract_vdate),l_contract_vdate)
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading