Have you ever needed to find specific data in your Oracle database but were unsure how to do it effectively? The LIKE statement is a powerful tool that lets you perform precise searches in your tables. In this guide, you will learn everything from the basics to advanced techniques for getting the most out of the Oracle LIKE statement.
What Is the LIKE Statement in Oracle?
The LIKE statement in Oracle is used to search for a specific pattern in a text column. It is especially useful when you do not know the exact value you are looking for but have an idea of the pattern it follows.
Basic Syntax
The basic syntax of the LIKE statement is:
SELECT column1, column2, ...
FROM table_name
WHERE column LIKE pattern;
Here, column is the column where you want to search, and pattern is the pattern you are looking for.
Wildcard Characters
Oracle allows wildcard characters in the LIKE statement to perform more flexible searches:
-
%: Represents zero or more characters. -
_: Represents a single character.
Basic Example
Imagine that you have a table called customers and want to find all names that start with J:
SELECT name
FROM customers
WHERE name LIKE 'J%';
This example finds all names that begin with the letter J.
Intermediate LIKE Searches
Now that we understand the basics, let us look at how to perform more specific searches.
Using Multiple Wildcards
You can use multiple wildcards in a search. For example, to find names that begin with A and end with n:
SELECT name
FROM customers
WHERE name LIKE 'A%n';
This example returns names such as Adrian or Alison.
Substring Searches
What if you need to find a specific substring inside a column? You can do this by using wildcards at the beginning and end of the pattern:
SELECT name
FROM customers
WHERE name LIKE '%son%';
This example returns names such as Jason and Alison.
Advanced LIKE Techniques
For advanced users, the LIKE statement can be combined with other Oracle functions and clauses to perform more complex searches.
Using LIKE with LOWER and UPPER
If you need a case-insensitive search, you can combine LIKE with the LOWER or UPPER functions:
SELECT name
FROM customers
WHERE LOWER(name) LIKE 'j%';
This example finds all names that begin with j, regardless of whether they are uppercase or lowercase.
Combining LIKE with AND and OR
You can combine multiple LIKE conditions using the AND and OR clauses to perform more complex searches:
SELECT name
FROM customers
WHERE name LIKE 'A%' AND name LIKE '%n';
This example finds names that begin with A and end with n.
Searching for Special Characters
To search for special characters such as the percent sign (%), you can use an escape character:
SELECT name
FROM customers
WHERE name LIKE '20\% off' ESCAPE '\';
This example searches for the text 20% off.
Conclusion
The LIKE statement in Oracle is an indispensable tool for any database administrator. From basic searches to advanced techniques, LIKE lets you find specific data efficiently. Whether you are a beginner or an expert, this guide gives you the tools needed to use the Oracle LIKE statement effectively.
Key Concepts Summary
-
Basic syntax:
SELECT column FROM table_name WHERE column LIKE pattern; -
Wildcards:
%(zero or more characters),_(a single character) -
Intermediate searches: Combining wildcards and substrings
-
Advanced techniques: Using
LOWER,UPPER, combinations withANDandOR, and special characters
Now that you have a thorough understanding of how to use the Oracle LIKE statement, why not try some examples in your database? You may be surprised by the flexibility and power of this simple but effective tool.

