IF-THEN-END IF

0



IF-THEN-END IF
Syntax:
          IF condition THEN
                   Sequences of statements;
          END IF;

Points to Ponder:
  • IF…THEN is a reserved word and marks the beginning of the “IF” statement.
  • The “END IF” is a reserved phrase that indicates the end of the “IF…THEN” construct.
  • When “IF…THEN” is executed, A condition is evaluated to either “TRUE” or “FALSE”.
  • Conditions are compared by using either the comparison operators or SQL*plus operators.
  • One “IF” keyword can manager any number of conditions at a point of time using the LOGICAL CONNECTIVITIES like “AND”, “OR”.
  • Even though the multiple conditions need not be constrained by using brackets, It is better to control their precedence using the proper implementations of brackets to avoid ambiguity.
  • Every “IF” that is implemented needs compulsorily a “TRUE” state evaluation for its successful execution, But an evaluation state is not compulsory when the condition is “FALSE”.
  • The sequence of statements is executed only if the condition evaluates to true.
  • If it is false or null, then the control passes to the statement after ‘END IF”.
Example:
SQL>BEGIN
                   IF ascii('A')=65 THEN
                             DBMS_OUTPUT.PUT_LINE('This is true');
                   END IF;
          END;


          DECLARE
                             Firstnum NUMBER:=&Fnum;
                             Secondnum NUMBER:=&Snum;
                             Temp NUMBER:
                   BEGIN
                   DBMS_OUTPUT.PUT_LINE('Original Firstnum='||Firstnum);
                   DBMS_OUTPUT.PUT_LINE('Original Secondnum='||Secondnum);
                   IF Firstnum>Secondnum THEN
                             TEMP:=Firstnum;
          Firstnum:=Secondnum;
          Secondnum:=Temp;
          END IF;
          DBMS_OUTPUT.PUT_LINE('Swapped Firstnum='||Firstnum);
          DBMS_OUTPUT.PUT_LINE('Swapped Firstnum='||Secondnum);
END;
/


 Click here to go to Back page

About the author

Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus. Aenean fermentum, eget tincidunt.

0 comments:

Recent Posts