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