Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Shortened equivalent for multiple LIKE conditions (or NOT LIKE)

AnneWAug 27 2021

Oracle RDBMS versin : 19c 

Question from a newbie :)

In the below example, to find values which do not match 'J%' AND 'K%' AND 'P%', I had to write a NOT LIKE '%' condition for each pattern.
In Oracle's SQL, can this be shortened ?

In the Linux world, to grep (GNU grep) for multiple patterns, I can do something like below 

grep -E 'John|Pattern2|Pattern3' myFile.txt 

I was wondering if there is something similair in SQL world :)

create table test465 
(empname varchar2(33),
 job_tile varchar2(35)
);

insert into test465 values ('JOHN', 'ACCOUNTANT');
insert into test465 values ('KATE', 'PROGRAMMER');
insert into test465 values ('KEITH', 'SYSTEM ADMIN');
insert into test465 values ('PABLO', 'HR ADMIN');
insert into test465 values ('BELINDA', 'MANAGER');
insert into test465 values ('PETER', 'DIRECTOR');


SELECT *
FROM  test465
WHERE empname NOT LIKE 'J%'
    AND empname NOT LIKE 'K%'
    AND empname NOT LIKE 'P%';

EMPNAME              JOB_TILE
--------------------------------- -------------------
BELINDA              MANAGER
This post has been answered by Frank Kulash on Aug 27 2021
Jump to Answer
Comments
Post Details
Added on Aug 27 2021
11 comments
10,586 views