| DECODE and NVL2 in WHERE clause (2 Merged) [message #539165] |
Wed, 11 January 2012 15:25  |
rkhatiwala
Messages: 178 Registered: April 2007
|
Senior Member |
|
|
oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
PL/SQL Release 11.1.0.6.0 - Production
"CORE 11.1.0.6.0 Production"
Hi,
I have following:
DECLARE
l_pin VARCHAR2(17);
l_event_no VARCHAR2(9);
l_causal_part_no VARCHAR2(15);
l_main_code VARCHAR2(8);
l_event_id WC_MAIN_EVENT.event_id%TYPE;
BEGIN
l_pin := '5NPET46C67H271471';
l_event_no := '058272000';
l_causal_part_no := '883013K020';
l_main_code := null;
SELECT event_id INTO l_event_id
FROM WC_MAIN_EVENT
WHERE event_group_id = 4
AND pin = l_pin
AND event_number = l_event_no
AND part_number = l_causal_part_no
AND nvl2(l_main_code,event_code,1) = nvl2(l_main_code,l_main_code, 1);
-- AND decode(l_main_code , NULL,1,event_code) = DECODE(l_main_code, NULL, 1, l_event_code);
dbms_output.put_line('l_event_id = '|| l_event_id);
EXCEPTION
when others then
dbms_output.put_line('error = '|| sqlerrm);
END ;
If I use DECODE, then it gives error ORA-01722: invalid number , but if I use NVL2, it works fine. What is the difference between these two ?
Thanks
|
|
|
|
|
|