Not Like in Where Clause for Oracle

In my where clause, I have a list of job codes to exclude.
In addition, they want to exclude anything that starts with VP.
I've tried the following code, but it is still retrieving VP job codes.
I really don't want to hard code it, but wanted to know if I'm writing the code correctly.


  and   (emp.job_code not in ('CONVP', 'EVP01', 'EVPF1', 'FEL01', 'FEL02', 'FEL03', 'FEL04', 'FEL05',  
                                       'FEL06', 'FEL07', 'FEL08', 'FEL09', 'FEL10', 'FEL12', 'FEL13', 'FEL14',  
                                       'FEL16', 'FEL17', 'FEL18', 'FEL19', 'INT01', 'INT02', 'INT03', 'INT05',  
                                       'MD-01', 'MD-02', 'MD-03', 'MD-04', 'MD-05', 'MD-06', 'MD-08', 'MDD01',
                                       'MDD02', 'MDD03', 'MDD04', 'MDD06', 'MDD09', 'MDD10', 'MDD11', 'MDD12',  
                                       'MDD13', 'MDD14', 'MDD15', 'MDD16', 'MDD17', 'MDD18', 'MDD19', 'MDD21',  
                                       'MDDC1', 'REM01', 'REM02', 'REM03')

                                        /*, 'VP-01', 'VP-02', 'VP-03', 'VP-04',
                                       'VP-06', 'VP-07', 'VP-08', 'VP-09', 'VP-10', 'VP-11', 'VP-12', 'VP-13',
                                       'VP-14', 'VP-15', 'VP-17', 'VP-18', 'VP-19', 'VP-20', 'VP-21', 'VP-22',
                  or emp.job_code not like '%VP-%')
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve WalesSenior Database AdministratorCommented:
Change the: OR emp.job_code not like '%VP-%')

To: AND emp.job_code not like '%VP-%')

Should do the trick - dealing with NOT's in the middle of that confuses AND and OR sometimes.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
slightwv (䄆 Netminder) Commented:
Change the or to an and?

  AND emp.job_code not like '%VP-%')
johnsoneSenior Oracle DBACommented:
I think you need an AND instead of an OR.

VP-06 is not in the list of codes you list in the first half of the OR, so the the query is satisfied there.
Mark GeerlingsDatabase AdministratorCommented:
I agree, use "and" instead of "or".

Now for the questions you didn't ask, but I think of when I see a question like this here:
1. Hopefully you are aware that a "not in" or "not exists" condition in an Oracle query prevents Oracle from using an index on that column, so the query performance may be poor (but this depends on lots of things).
2. A more flexible approach that I like to use for queries like this, that will not require hard-coding values in the report (and recompiling, re-deploying, etc.) would be to set up an exclusion table that you link to with a "not in" sub-query.  Then you simply need a data entry screen (or some other easy tool) to add or remove records from that table when necessary, to change which values get included or excluded from the report(s).
metalteckAuthor Commented:
Thanks for the help and explanation all.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.