2013-07-24 40 views
0

大家好我有一個相當簡單的問題。Oracle - AND之間的區別(Case1或Case2或Case3)

我想知道什麼

SELECT * 
    FROM TABLE 
WHERE A = 'xxx' 
    AND (B = 'xxx' OR C='xxx' OR D='xxx') 

而這個查詢

SELECT * 
    FROM TABLE 
WHERE A = 'xxx' 
    AND B = 'xxx' 
    OR C='xxx' 
    OR D='xxx' 

之間的差別在底部的查詢將返回2個結果與上面的查詢返回結果爲零。

回答

2

SELECT * FROM TABLE 
WHERE A = 'xxx' AND (B = 'xxx' OR C='xxx' OR D='xxx') 

相當於該

SELECT * FROM TABLE 
WHERE A = 'xxx' AND B = 'xxx' OR 
     A = 'xxx' AND C = 'xxx' OR 
     A = 'xxx' AND D = 'xxx' 

你把在WHERE子句遵循布爾表達式規則的邏輯。就像代數表達式一樣,有一個命令操作。一般情況下,順序是

相關問題