if else syntax [message #337905] |
Fri, 01 August 2008 09:25  |
shoaib123
Messages: 118 Registered: December 2007 Location: Chicago
|
Senior Member |
|
|
Is there any difference between these 2 syntax's..
|
|
|
|
|
Re: if else syntax [message #337919 is a reply to message #337907] |
Fri, 01 August 2008 10:07   |
shoaib123
Messages: 118 Registered: December 2007 Location: Chicago
|
Senior Member |
|
|
I don't see any difference, except using "end" at the end of statement.
begin
if :new.col4 = 6
then
:new.col4 := 60;
else if
:new.col4 = 7
then :new.col4 := 70;
else
:new.col4 := 80;
end if;
end if;
end;
begin
if :new.col4 = 6
then
:new.col4 := 60;
elsif
:new.col4 = 7
then :new.col4 := 70;
else
:new.col4 := 80;
end if;
end;
Please validate this if i m right..
Appreciate your time on this..
|
|
|
|
|
|
|
|
Re: if else syntax [message #337939 is a reply to message #337927] |
Fri, 01 August 2008 11:54   |
shoaib123
Messages: 118 Registered: December 2007 Location: Chicago
|
Senior Member |
|
|
If any of the "if" condition fails it jump to the next one.That is exactly happening in both situations using elsif and else if..
What could be the difference.. Is anybody can throw little clue plz..
|
|
|
|
Re: if else syntax [message #337959 is a reply to message #337942] |
Fri, 01 August 2008 13:44   |
shoaib123
Messages: 118 Registered: December 2007 Location: Chicago
|
Senior Member |
|
|
>>> ELSE IF is logical AND for nested IFs
IF sales > (quota + 200) THEN
bonus := (sales - quota)/4;
ELSE
IF sales > quota THEN
bonus := 50;
end if;
end if;
In this situation,(Please correct me, if i m wrong) it means if the first "if" condition executes as true then it will execute the next step only. If the first "if" condition execute as null or false it will go to "end if".
>> ELSIF is logical OR for nested IFs
BEGIN
IF grade = 'A' THEN
DBMS_OUTPUT.PUT_LINE('Excellent');
ELSIF grade = 'B' THEN
DBMS_OUTPUT.PUT_LINE('Very Good');
ELSIF grade = 'C' THEN
DBMS_OUTPUT.PUT_LINE('Good');
end if;
In this situation(please correct me if i am wrong), it means if the first "if" condition execute as false, then it will go to next "if" condition,
I appreciate your time and help to validate this...
|
|
|
Re: if else syntax [message #337977 is a reply to message #337919] |
Fri, 01 August 2008 21:15  |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
shoaib123 wrote on Fri, 01 August 2008 17:07 | Please validate this if i m right..
| Validate what? That they return the same result?
They do, but if you had any doubt you would surely run it to prove this; so there must be more something beyound this question.
By the way, the formatting of the first codes is quite strange; I wonder whether it is transparent for you (you can easily find the desired information and accordingly modify it).
Maybe you will see the ELSIF advantage if you use PL/SQL Formatter:
BEGIN
IF :new.col4 = 6 THEN
:new.col4 := 60;
ELSE
IF :new.col4 = 7 THEN
:new.col4 := 70;
ELSE
:new.col4 := 80;
END IF;
END IF;
END;
BEGIN
IF :new.col4 = 6 THEN
:new.col4 := 60;
ELSIF :new.col4 = 7 THEN
:new.col4 := 70;
ELSE
:new.col4 := 80;
END IF;
END;
|
|
|