Oracle PL/SQL - Escape Character in Pattern

Introduction

To search for the percent sign or underscore, define an escape character and put it before the percent sign or underscore.

The following code uses the backslash as the escape character, so that the percent sign in the string does not act as a wildcard.

Demo

SQL>
SQL> DECLARE--   w  w w  .j  a  v a  2s. co  m
  2    PROCEDURE my_proc (sale_sign VARCHAR2) IS
  3    BEGIN
  4      IF sale_sign LIKE '50\% off!' ESCAPE '\' THEN
  5        DBMS_OUTPUT.PUT_LINE ('TRUE');
  6      ELSE
  7        DBMS_OUTPUT.PUT_LINE ('FALSE');
  8      END IF;
  9    END;
 10  BEGIN
 11    my_proc('this is a test!');
 12    my_proc('50% off!');
 13    my_proc('50!');
 14  END;
 15  /
FALSE
TRUE
FALSE

PL/SQL procedure successfully completed.

SQL>
SQL>

Related Topic