Sie sind auf Seite 1von 2

SQL>

SQL>
SQL> -- Using nested IF statements.
SQL> DECLARE
2 v_HoursWorked Number := 80 ;
3 v_OverTime Number := 0 ;
4 v_PayType char(1) := 'E';
5
6 BEGIN
7 IF v_HoursWorked > 40 THEN
8 IF v_PayType = 'H' THEN
9 v_OverTime := v_HoursWorked - 40;
10 DBMS_OUTPUT.PUT_LINE('Hours overtime worked = ' || v_OverTime);
11 ELSE
12 IF v_PayType = 'S' THEN
13 DBMS_OUTPUT.PUT_LINE('Employee is Salaried');
14 ELSE
15 DBMS_OUTPUT.PUT_LINE('Employee is Executive Management');
16 END IF;
17 END IF;
18 END IF;
19 END;
20 /
Employee is Executive Management

PL/SQL procedure successfully completed.

[sql]DECLARE
v_deptno NUMBER (2) ;
v_name VARCHAR2 (100) := SALES ;
BEGIN
SELECT deptno
INTO v_deptno
FROM dept
WHERE dname = v_name;
DBMS_OUTPUT.PUT_LINE (Department Number fetched is ||v_deptno);
IF (v_deptno > 20 ) THEN
DBMS_OUTPUT.PUT_LINE (Department Number is greater than 20);
IF (v_deptno = 30) THEN
DBMS_OUTPUT.PUT_LINE (We are in Department Number 30);
ELSE
IF (v_deptno = 40) THEN
DBMS_OUTPUT.PUT_LINE (We are in Department Number 40);
END IF;
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE (Department Number is less than or equal to 20);
IF (v_deptno = 20) THEN
DBMS_OUTPUT.PUT_LINE (We are in Department Number 20);
ELSE
IF (v_deptno = 10) THEN
DBMS_OUTPUT.PUT_LINE (We are in Department Number 10);
END IF;
END IF;
END IF;
END;[/sql]
+

Output:-+

Department Number fetched is - 30


Department Number is greater than 20
We are in Department Number 30

Deptno for DeptnameSALES is 30. In the above example, We have multiple IF statements one in another. i.e. based on the Deptno program
evaluates first IF condition i.e > 20 and proceeding with the execution of child IF statements.

Das könnte Ihnen auch gefallen