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!

IF and Else executing both at same time.

934101Apr 28 2015 — edited Apr 28 2015

Hi Everyone,

I have one strange problem in below small piece of code, both if and else blocks are execution at same time.

Kindly advise on this strange behavior.

DECLARE

p_year varchar2(4) := 9999;

BEGIN

FOR i IN (SELECT meaning, lookup_code FROM fnd_lookup_values

         WHERE lookup_type = 'PARALLEL_ALLOCATION')

loop

DBMS_OUTPUT.PUT_LINE(i.meaning ||'-'|| i.lookup_code);

IF i.meaning = p_year THEN

DBMS_OUTPUT.PUT_LINE('Year Values now');

DBMS_OUTPUT.PUT_LINE(i.meaning ||'-'|| p_year);

else

DBMS_OUTPUT.PUT_LINE('Year Values in else');

DBMS_OUTPUT.PUT_LINE(i.meaning ||'-'|| p_year);

end if;

end loop;       

END;

/

OUTPUT-

9999-2012

Year Values now

9999-9999

8888-2016

Year Values in else

8888-9999

Select used in for loop is having two values only i.e.

meaning lookup_code

9999      2012

8888      2016

Expected output should be in IF portion i.e. and else portion should not execute.

9999 and 2012 from DBMS_OUTPUT

This post has been answered by PeterValencic on Apr 28 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 26 2015
Added on Apr 28 2015
16 comments
2,226 views