Arn*_*ldo 7 sql oracle oracle19c
我在跑步Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.8.0.0.0。
考虑以下示例:
create table tab_a as
select 1 as id from dual
union all select 2 as id from dual
union all select 3 as id from dual
;
create table tab_b as
select 1 as id, 'b1' as val, 'bbb1' as val_b from dual
union all select 2 as id, 'b2' as val, 'bbb2' as val_b from dual
;
create table tab_c as
select 1 as id, 'c1' as val, 'ccc1' as val_c from dual
union all select 3 as id, 'c3' as val, 'ccc1' as val_c from dual
;
select
a.id
,b.val
,b.val_b
,b.val_c
from
tab_a a
left join tab_b b on b.id = a.id
left join tab_c b on b.id = a.id
order by
a.id
;
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我在另一个表上重复使用了“b”别名(重复)。这是结果:
ID VAL VAL_2 VAL_3
---------- ---------- ---------- ----------
1 b1 bbb1 ccc1
2 b2 bbb2 (null)
3 (null) (null) ccc1
Run Code Online (Sandbox Code Playgroud)
所以:
看来 Oracle 为两个表分配了优先级别名,并且不会将其报告为语法错误。但这是我想避免的。我很惊讶在我的查询中发现了这个错误。这种行为是已知的吗?可以采取什么措施来强制使用唯一的别名吗?
小智 0
由于我的声誉,我无法发表评论,但最近遇到了这个问题,并想提及已在 23c 上修复。
SQL> select
2 a.id
3 ,b.val
4 ,b.val_b
5 ,b.val_c
6 from
7 tab_a a
8 left join tab_b b on b.id = a.id
9 left join tab_c b on b.id = a.id
10 order by
11 a.id
12 ;
,b.val
*
ERROR at line 3:
ORA-00918: column ambiguously defined
Run Code Online (Sandbox Code Playgroud)