DECODE returns NULL in where clause
If some one can help, this is bit weird problem.
An existing code is failing, and returns NULL value. When checked, it works fine in TEST database, but fails in PROD????
Check the following SQL:
----------------------------------
select tpr_price from r5taskprices
where tpr_org = decode(:p_common, '-', '*', '*');
--- where :p_common is a parameter and NULL value is passed at runtime.
----------------------------------
The TPR_ORG column is of VARCHAR2 type, and have unique value = '*'.
The above query was working fine in PROD env, and now without any change in data, patch or upgrade, the same query returns NULL.
Below are couple of test cases, which returns the valid records after modifying the same query in PROD:
1. Use of NVL function
select tpr_price from r5taskprices
where tpr_org = decode(nvl(:p_common,''), '-', '*', '*');
2. Use of LTRIM and RTRIM function
(even though the max length of TPR_ORG = 1 )
select tpr_price from r5taskprices
where ltrim(rtrim(tpr_org)) = decode(:p_common, '-', '*', '*');
Any help will be really appreciated.
Thanks.