Oracle PL/SQL - IN Operator for membership

Introduction

The IN operator tests set membership.

x IN (set) returns TRUE only if x equals a member of set.

The following code prints the values of expressions that include the IN operator.

Demo

SQL>
SQL> CREATE OR REPLACE PROCEDURE print_boolean (
  2    b_name   VARCHAR2,--   w ww. jav a 2  s  .  c o  m
  3    b_value  BOOLEAN
  4   ) IS
  5  BEGIN
  6    IF b_value IS NULL THEN
  7      DBMS_OUTPUT.PUT_LINE (b_name || ' = NULL');
  8    ELSIF b_value = TRUE THEN
  9      DBMS_OUTPUT.PUT_LINE (b_name || ' = TRUE');
 10    ELSE
 11      DBMS_OUTPUT.PUT_LINE (b_name || ' = FALSE');
 12    END IF;
 13  END;
 14  /

Procedure created.

SQL> DECLARE
  2    letter VARCHAR2(1) := 'm';
  3  BEGIN
  4    print_boolean('letter IN (''a'', ''b'', ''c'')',letter IN ('a', 'b', 'c'));
  5    print_boolean('letter IN (''m'', ''y'')',letter IN ('m', 'y'));
  6  END;
  7  /
letter IN ('a', 'b', 'c') = FALSE
letter IN ('m', 'y') = TRUE

PL/SQL procedure successfully completed.

SQL>
SQL>

Related Topics