DROP TABLE table1;
DROP TABLE table2;
CREATE TABLE table1
( col1 NUMBER,
col2 NUMBER,
col3 NUMBER,
col4 NUMBER
);
CREATE TABLE table2
( col1 NUMBER,
col2 NUMBER,
col3 NUMBER,
col4 NUMBER
);
INSERT INTO TABLE1 VALUES (1,44,1,1);
INSERT INTO table1 VALUES (2,44,2,2);
INSERT INTO TABLE1 VALUES (3,44,3,3);
INSERT INTO table2 VALUES (1,44,11,11);
INSERT INTO TABLE2 VALUES (2,44,22,22);
-- Q1
SELECT t1.*, t2.* FROM table1 t1, table2 t2
WHERE t1.col1 = t2.col1(+);
-- Yields
-- col1 col2 col3 col4 col1_1 col2_1 col3_1 col4_1
1 44 1 1 1 44 11 11
2 44 2 2 2 44 22 22
3 44 3 3 NULL NULL NULL NULL
-- Q2
SELECT t1.*, t2.* FROM table1 t1, table2 t2
WHERE t1.col1 = t2.col1(+)
AND t2.col1 IS NULL;
-- Yields
-- col1 col2 col3 col4 col1_1 col2_1 col3_1 col4_1
3 44 3 3 NULL NULL NULL NULL
-- Q3
SELECT t1.*, t2.* FROM table1 t1, table2 t2
WHERE t1.col2 = 44
AND t2.col2 = 44
AND t1.col1 = t2.col1(+)
AND t2.col1 IS NULL;
-- Yields
-- col1 col2 col3 col4 col1_1 col2_1 col3_1 col4_1
-- No Rows.
COMMIT;
答案 0 :(得分:2)
因为t2.col1 IS NULL
和t2.col2 = 44
不会同时成立。
如果t2.col1 IS NULL
,则表示联接不匹配,因此t2.col2
也将是NULL
。
答案 1 :(得分:0)
t2.col2不可能是44,如果您没有从整个桌子的左连接中获得结果,则会在WHERE
中进行检查!