Oracle
NOT LIKE Operator
The NOT LIKE operator in Oracle is used in SQL queries to filter records based on pattern matching. It allows you to select rows where a specified column's value does not match a particular pattern. This operator is especially useful when dealing with text data, enabling you to exclude unwanted records based on specific criteria.
Key Points about the NOT LIKE Operator
Basic Syntax:
- The basic syntax for the
NOT LIKEoperator is:SELECT column_name FROM table_name WHERE column_name NOT LIKE 'pattern';
- The basic syntax for the
Wildcard Characters:
- You can use two wildcard characters with the
NOT LIKEoperator:%: Represents zero or more characters._: Represents a single character.
- Example:
This query retrieves all books whose titles do not start with the letter "A".SELECT * FROM books WHERE title NOT LIKE 'A%';
- You can use two wildcard characters with the
Example with Authors Table:
- Here's an example using an authors table to find authors whose names do not start with "John":
SELECT * FROM authors WHERE author_name NOT LIKE 'John%';
- Here's an example using an authors table to find authors whose names do not start with "John":
Case Sensitivity:
- The
NOT LIKEoperator is case-sensitive in Oracle. To perform a case-insensitive search, you can use theUPPERorLOWERfunctions. - Example:
SELECT * FROM members WHERE UPPER(member_name) NOT LIKE 'A%';
- The
Combining Conditions:
- You can combine the
NOT LIKEoperator with other conditions usingANDorOR. - Example:
SELECT * FROM rentals WHERE rental_status NOT LIKE 'Returned%' AND rental_date NOT LIKE '2024%';
- You can combine the
Best Practices
Use Wildcards Wisely:
- Avoid leading wildcards (e.g.,
%text) as they can lead to performance issues since they prevent the use of indexes.
- Avoid leading wildcards (e.g.,
Optimize Queries:
- Use the
NOT LIKEoperator judiciously in large datasets. Consider indexing columns that are frequently queried with this operator for better performance.
- Use the
Test Patterns:
- Always test your patterns with sample data to ensure the expected results are returned, especially when using wildcard characters.
Consider Case Sensitivity:
- Be mindful of case sensitivity in your queries and adjust accordingly using string functions when necessary.
By understanding the NOT LIKE operator, you can effectively filter data in Oracle databases, ensuring you retrieve only the relevant records for your queries.
To gain complete access, login with gmail or outlook, no need of signup. click here
TEST CODE
In Oracle, to fetch records for clients whose last names do not start with 'M%', where '%' indicates the potential presence of zero or more characters following 'M', you can use the following query:
SELECT *
FROM org_client
WHERE last_name NOT LIKE 'M%';In Oracle, to retrieve entries for clients whose first names do not conclude with 'e', you can use the following query:
SELECT *
FROM org_client
WHERE first_name NOT LIKE '%e';Example 1:
Explore the procedure of retrieving data from a designated table using the SQL NOT LIKE operator. Fetch records for clients whose last names do not start with 'M%', where '%' indicates the potential presence of zero or more characters following 'M'.
Example 1 - Raw data from client table

Example 1 - Query
SELECT *
FROM org_client
WHERE last_name NOT LIKE 'M%';Example 1 - Query data mapping

In the provided image, the green color signifies the data that has been selected or satisfies the conditions specified in our query. Data points in red indicate information that does not meet the criteria set by the query.
Example 1 - Query Output

Example 2:
Retrieve entries for clients whose first names do not conclude with '%e'.
Example 2 - Query
SELECT *
FROM org_client
WHERE first_name NOT LIKE '%e';Example 2 - Query data mapping

In the provided image, the green color signifies the data that has been selected or satisfies the conditions specified in our query. Data points in red indicate information that does not meet the criteria set by the query.
Example 2 - Query Output



Comments Not Found