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?
>Solution :
With a bit reformulation based on the rules of Aristoteles you may write
- you allways want the
end_dateis greather than yourgreatestexpression
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)
)