Oracle PL/SQL - PL SQL Statement NULL Statement

Introduction

The NULL statement only passes control to the next statement.

In the following code, the NULL statement emphasizes that only salespersons receive commissions.

Demo

SQL>
SQL> drop TABLE emp;
SQL>-- from   w w  w .  j  ava 2  s  . c  o  m
SQL> CREATE TABLE emp(
  2  empid NUMBER(6),
  3  first_name VARCHAR2(20),
  4  last_name VARCHAR2(25)) ;
SQL>
SQL> INSERT INTO emp VALUES( 100, 'Steven', 'King');
SQL> INSERT INTO emp VALUES( 101, 'Mary', 'Smith');
SQL> DECLARE
  2    v_job_id  VARCHAR2(10);
  3    v_emp_id  NUMBER(6) := 110;
  4  BEGIN
  5    SELECT empid INTO v_job_id
  6    FROM emp
  7    WHERE empid = v_emp_id;
  8
  9    IF v_job_id = '001' THEN
 10      UPDATE emp
 11      SET commission_pct = commission_pct * 1.2;
 12    ELSE
 13      NULL;  -- Employee is not a sales rep
 14    END IF;
 15  END;
 16  /

SQL>

Related Topics