Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DECODE returns NULL in where clause

SKV_585724Aug 20 2007 — edited Aug 21 2007
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2007
Added on Aug 20 2007
16 comments
2,496 views