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 statement using nvl function

User297968Jul 10 2012 — edited Jul 10 2012
I have inherited some code that using a decode and nvl. I'm unsure the purpose of it and want confirmation that it is flawed logic and a mistake. The situation can be recreated by setting up the following.

CREATE TABLE XX_TEST
(ID NUMBER,
FIELD VARCHAR2(255)
)

INSERT INTO XX_TEST(ID,FIELD) VALUES (1,'Yes')
INSERT INTO XX_TEST(ID,FIELD) VALUES (2,'No')
INSERT INTO XX_TEST(ID,FIELD) VALUES (3,NULL)

commit

SELECT ID,
FIELD,
DECODE(FIELD,'Yes','Yes Result do this', NVL(FIELD,'No'),'No result do this','catch all result do this')
FROM XX_TEST

I'm unsure of the NVL(FIELD,'No') I think the creator maybe thought this would catch the nulls but it doesn't.
The values Null is not converted to No and instead drops into the catch all. Can anyone help with an explaination of of how oracle is interpretting the select statement. Any ideas on why NVL would be used like this? Seems a mistake?
This post has been answered by chris227 on Jul 10 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 7 2012
Added on Jul 10 2012
6 comments
10,784 views