Oracle Wildcard Characters
Version 18.1.0.0

General Information
Library Note Morgan's Library Page Header
"We don't live in a dictatorship or a monarchy. I swore an oath in the military and in the Senate to preserve, protect and defend the Constitution of the United States, not to mindlessly cater to the whims of Cadet Bone Spurs and clap when he demands I clap,"
~ Sen. Tammy Duckworth
Purpose Make possible fuzzy search criteria in the SELECT statement's WHERE clause
 
Demo Table And Records
Demo Data conn uwclass/uwclass@pdbdev

CREATE TABLE wildcard (
test VARCHAR2(25));

INSERT INTO wildcard VALUES ('23%45');
INSERT INTO wildcard VALUES ('2345');
INSERT INTO wildcard VALUES ('2365');
INSERT INTO wildcard VALUES ('Daniel Morgan');
INSERT INTO wildcard VALUES ('Washington');
COMMIT;
SELECT *
FROM wildcard
WHERE test LIKE '%\%%' ESCAPE '\';
Wildcard Characters
Single Character _ (underscore)
SELECT *
FROM wildcard
WHERE test LIKE '23_5';
Multiple Characters % (percentage sign)
SELECT *
FROM wildcard
WHERE test LIKE '2%5';
Mixed Single And Multiple Characters SELECT *
FROM wildcard
WHERE test LIKE '_3%5';
Complex Statement SELECT *
FROM wildcard
WHERE test LIKE '%a%a %';
 
Querying Records Containing Wildcards
Find Records Containing Percentage Sign ESCAPE '<escape_character>'
SELECT *
FROM wildcard
WHERE test LIKE '%\%%' ESCAPE '\';
Find values beginning with an underscore character ESCAPE '<escape_character>'
SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc DESCRIPTION
FROM x$ksppi x, x$ksppcv y
WHERE x.inst_id = userenv('Instance')
AND y.inst_id = userenv('Instance')
AND x.indx = y.indx
AND x.ksppinm like '\_b%' ESCAPE '\'
ORDER BY 1;

Related Topics
Built-in Functions
Built-in Packages
DELETE Statements
DML Statements
INSERT Statements
MERGE Statements
SELECT Statements
UPDATE Statements
WHERE Clause
What's New In 12cR2
What's New In 18cR1