Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

oracle - I am trying to create a SQL query with multiple AND OR and NOT LIKE commands

I am trying to do this query (updated after comments)

SELECT item,short,itemgr FROM DATABASE.ITEM
WHERE marker = 0 and
      itemgr in ('200','201','202','204','205','230','234','236','240','270','285') and
      short NOT LIKE '%AQUA%';

The results vary. If I use NOT LIKE after the first bracket with 1 parameter it works (as you can see it in the sample now), but as soon as I try to add a second NOT LIKE command I just get the results from the first bracket.

EDIT

Original SQL:

SELECT item,short,itemgr FROM DATABASE.ITEM
WHERE
 marker = 0 AND (itemgr = '100' OR itemgr = '301' OR itemgr = '405')
AND
(short NOT LIKE '%A%' OR short NOT LIKE '%B%' OR short NOT LIKE '%A%');
question from:https://stackoverflow.com/questions/65626283/i-am-trying-to-create-a-sql-query-with-multiple-and-or-and-not-like-commands

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to get items that don't match a series of like conditions, I would suggest regular expressions. Perhaps what you want is:

SELECT item, short, itemgr
FROM DATABASE.ITEM i
WHERE i.marker = 0 and
      i.itemgr in ('200', '201', '202', '204', '205', '230', '234', '236', '240', '270', '285') and
      not regexp_like(short, 'AQUA|TERRA')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...