为什么Oracle SQL神秘地解决一个联接中的歧义而不解决其他联接中的歧义
技术问答
64 人阅读
|
0 人回复
|
2023-09-13
|
我是Oracle10g用户。我必须写一些。SQL查询,发现一个神秘的行为(如我所见)。假设我们有一个表,它可以连接到一个简单的两级树结构。预计下一个查询会给我歧义错误:4 Y6 \, N- u8 Q5 f) @- C( g8 V
select title from table1 left join table1 on condition然而,如果我想在联系中添加另一个表,歧义问题将简单地消失:$ ?) h, C5 t1 i7 _ v
select title from table1 join table2 on other_condition left join table1 on condition对此有什么解释?我完全想念它…可以使用完整的测试用例http://pastebin.com/webf513w中找到) ~( ? |2 l% {9 H, t/ H( N3 W& T" @
0 f Y1 ^- i h5 ^
解决方案:
2 J, d# n' o0 C3 n4 E0 c) n0 M 第三个查询,Oracle 10g从第二个TestTable1(别名TestTable1_2)返回field3.这似乎是一个错误,似乎是11g中修复。
& X# _4 {0 F y& D, `测试用例:
; J0 S; ~0 Q, S: H$ yINSERT INTO TestTable1 VALUES (1,2,3,NULL);INSERT INTO TestTable1 VALUES (2,5,6,1);INSERT INTO TestTable2 VALUES (5、6、7);INSERT INTO TestTable2 VALUES (2,20,30);SELECT field3FROM TestTable1join TestTable2 ON TestTable1.field1 = TestTable2.field1left join TestTable1 TestTable1_2 ON TestTable1.self_ref = TestTable1_2.id;FIELD3======3(null)SELECT TestTable1.field3,TestTable2.field3,TestTable1_2.field3FROM TestTable1join TestTable2 ON TestTable1.field1 = TestTable2.field1left join TestTable1 TestTable1_2 ON TestTable1.self_ref = TestTable1_2.id;FIELD3 FIELD3_1 FIELD3_2====== ======== ======== 6 333 3333333330 33333330 333333(null) |
|
|
|
|
|