我需要一些关于我写的SELECT
声明的帮助。
声明如下:
SELECT DISTINCT MANDT, PATH301
FROM NC301B
WHERE EDIPROC like 'P30_'
AND (LF301M > 0)
AND (MANDT LIKE '011')
AND (PATH301 NOT LIKE '%:\saptemp%')
AND (PATH301 NOT LIKE '%:\SAPTEMP%')
AND (PATH301 NOT LIKE '%usr%')
AND (PATH301 NOT LIKE '%:\Windows%')
AND (PATH301 NOT LIKE '%PKV_DAV%')
AND (PATH301 NOT LIKE '%pkv_dav%');
现在我需要检查额外的MANDT
- > MANDT LIKE '012'
我的问题是,当我将OR (MANDT LIKE '012')
行添加到语句时输出不正确。
我的想法是:
SELECT DISTINCT MANDT, PATH301
FROM NC301B
WHERE EDIPROC like 'P30_'
AND (LF301M > 0)
AND (MANDT LIKE '011')
OR (MANDT LIKE '012')
AND (PATH301 NOT LIKE '%:\saptemp%')
AND (PATH301 NOT LIKE '%:\SAPTEMP%')
AND (PATH301 NOT LIKE '%usr%')
AND (PATH301 NOT LIKE '%:\Windows%')
AND (PATH301 NOT LIKE '%PKV_DAV%')
AND (PATH301 NOT LIKE '%pkv_dav%');
是否可以在一个语句中检查两个或更多MANDT
个值
就像我在我的例子中所做的那样
谢谢!
答案 0 :(得分:3)
你需要注意括号,试试这个
SELECT DISTINCT MANDT, PATH301 FROM NC301B WHERE EDIPROC like
'P30_'
AND (LF301M > 0)
AND (MANDT LIKE '011' OR MANDT LIKE '012')
AND (PATH301 NOT LIKE '%:\saptemp%')
AND (PATH301 NOT LIKE '%:\SAPTEMP%')
AND (PATH301 NOT LIKE '%usr%')
AND (PATH301 NOT LIKE '%:\Windows%')
AND (PATH301 NOT LIKE '%PKV_DAV%')
AND (PATH301 NOT LIKE '%pkv_dav%');
答案 1 :(得分:2)
在MANDT
上的两张支票上放置括号:
SELECT DISTINCT MANDT, PATH301
FROM NC301B
WHERE EDIPROC LIKE 'P30_' AND
(LF301M > 0) AND
((MANDT LIKE '011') OR (MANDT LIKE '012')) AND
(PATH301 NOT LIKE '%:\saptemp%') AND
(PATH301 NOT LIKE '%:\SAPTEMP%') AND
(PATH301 NOT LIKE '%usr%') AND
(PATH301 NOT LIKE '%:\Windows%') AND
(PATH301 NOT LIKE '%PKV_DAV%') AND
(PATH301 NOT LIKE '%pkv_dav%');
答案 2 :(得分:2)
您需要使用括号对两个谓词进行分组,因为and
的优先级高于or
:
...
AND ( (MANDT LIKE '011') OR (MANDT LIKE '012') )
...
答案 3 :(得分:0)
您可以使用REGEXP_LIKE,因为您没有在' 011'和' 012',您可以使用IN Condition:
SELECT DISTINCT MANDT, PATH301
FROM NC301B
WHERE EDIPROC LIKE 'P30_'
AND LF301M > 0
AND MANDT IN ('011','012')
AND NOT regexp_like(path301, '(:\\saptemp|:\\SAPTEMP|usr|:\\Windows|PKV_DAV|pkv_dav)')
由于:
默认区分大小写由NLS_SORT参数的值确定。
你可以在regexp_like中使用第三个参数:
'我'指定不区分大小写的匹配。
' C'指定区分大小写的匹配。