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!

how to use IN and NOT LIKE operator together

anand_gpDec 14 2017 — edited Dec 15 2017

Hi,

I would like to know how to use IN and NOT LIKE operator together in the query. (Oracle XE 11g)  For example -

CREATE TABLE T1 (CODE VARCHAR2(10));

INSERT INTO T1 VALUES('01');

INSERT INTO T1 VALUES('01001');

INSERT INTO T1 VALUES('01002');

INSERT INTO T1 VALUES('02');

INSERT INTO T1 VALUES('02005');

INSERT INTO T1 VALUES('02008');

CREATE TABLE T2 (CODE VARCHAR2(10));

INSERT INTO T2 VALUES('02');

INSERT INTO T2 VALUES('05');

If I use

SELECT t1.*

FROM   t1, t2

WHERE  t1.code like t2.code||'%';

I get valid result i.e.

CODE
02
02005
02008

However, what I need is, NOT LIKE operator which should return only below values from T1 table (i.e. exclude everything from T1 table which matches with T2.CODE i.e.  02% and 05% -

01

01001

01002

I tried with below query which is, of course not correct one -

SELECT t1.*

FROM   t1, t2

WHERE  t1.code NOT like t2.code||'%';

Can someone help please.  Thanks.

Regards,

-Anand

This post has been answered by mathguy on Dec 14 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 12 2018
Added on Dec 14 2017
12 comments
2,287 views