O'Reilly logo

Oracle® PL/SQL® Interactive Workbook, Second Edition by Elena Silvestrova, Benjamin Rosenzweig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lab 5.3 Nested IF Statements

Lab Objectives

After this Lab, you will be able to:

Use Nested IF Statements

You have encountered different types of conditional controls: IF-THEN statement, IF-THEN-ELSE statement, and ELSIF statement. These types of conditional controls can be nested inside of another—for example, an IF statement can be nested inside an ELSIF and vice versa. Consider the following:

FOR EXAMPLE

DECLARE 
   v_num1 NUMBER := &sv_num1; 
   v_num2 NUMBER := &sv_num2; 
   v_total NUMBER; 
BEGIN 
   IF v_num1 > v_num2 THEN 
      DBMS_OUTPUT.PUT_LINE ('IF part of the outer IF'); 
      v_total := v_num1 - v_num2; 
   ELSE 
      DBMS_OUTPUT.PUT_LINE ('ELSE part of the outer IF'); 
      v_total := v_num1 + v_num2; 

      IF v_total < 0 THEN
					DBMS_OUTPUT.PUT_LINE ('Inner IF');
					v_total ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required