Skip to content

Oracle LIKE & Wildcards πŸ”ΒΆ

Prerequisites: WHERE Clause

Mentor's Note: What if you only remember that a student's name starts with "Vi"? You can't use =, but you can use LIKE. It's the search engine of the database world. πŸ’‘


🌟 The Scenario: The Smudged Record πŸ“„ΒΆ

Imagine an old file where the end of the name is unreadable. You only see "Sma...". - Action: You search for LIKE 'Sma%'. - Result: You find "Smart", "Small", and "Smathers".


πŸ’» 1. The Wildcard ToolsΒΆ

Wildcard Meaning Analogy
% Zero or more characters The "Infinite Bridge" πŸŒ‰
_ Exactly one character The "Single Footstep" πŸ‘£

ExamplesΒΆ

-- Starts with 'A'
SELECT name FROM students WHERE name LIKE 'A%';

-- Has 'sh' anywhere
SELECT name FROM students WHERE name LIKE '%sh%';

-- 4 letter name starting with 'R'
SELECT name FROM students WHERE name LIKE 'R___';

πŸ—οΈ Architect's Note: The Index Trap πŸ›‘οΈΒΆ

In Oracle, if you start your pattern with a wildcard (e.g., LIKE '%son'), the database cannot use an index. It must read the whole table. - Architect's Advice: Always try to put text before the wildcard if performance matters! LIKE 'Son%' is much faster than LIKE '%Son%'.


πŸ“ˆ Learning PathΒΆ