Oracle PL/SQL - LIKE Operator in IF statement

Introduction

The LIKE operator compares a character, string, or CLOB value to a pattern.

It returns TRUE if the value matches the pattern and FALSE if it does not.

The pattern can include the two wildcard characters underscore (_) and percent sign (%).

Underscore matches exactly one character.

Percent sign (%) matches zero or more characters.

Case is significant. The string 'Jason' matches the pattern 'J%s_n' but not 'J%S_N'.

Demo

SQL>
SQL> DECLARE-- from w  w  w. j  av a2s  .c o m
  2    PROCEDURE compare (
  3      value   VARCHAR2,
  4      pattern VARCHAR2
  5    ) IS
  6    BEGIN
  7      IF value LIKE pattern THEN
  8        DBMS_OUTPUT.PUT_LINE ('TRUE');
  9      ELSE
 10        DBMS_OUTPUT.PUT_LINE ('FALSE');
 11      END IF;
 12    END;
 13  BEGIN
 14    compare('Jason', 'J%s_n');
 15    compare('Jason', 'J%S_N');
 16  END;
 17  /
TRUE
FALSE

PL/SQL procedure successfully completed.

SQL>

Related Topics