如果有人让你实现笛卡儿积的时候,也许很多人都会想到如下这种做法。
WANGZK>select * from table_one;
COL_ONE COL_TWO
---------- ----------
1 one
2 two
5 five
WANGZK>select * from table_two;
COL_THREE COL_FOUR
---------- ----------
10 ten
20 twenty
5 five
WANGZK>select * from table_one,table_two;
COL_ONE COL_TWO COL_THREE COL_FOUR
---------- ---------- ---------- ----------
1 one 10 ten
1 one 20 twenty
1 one 5 five
2 two 10 ten
2 two 20 twenty
2 two 5 five
5 five 10 ten
5 five 20 twenty
5 five 5 five
已选择9行。
那我在描述一个另外的方法,那就是交叉关联。
WANGZK>select * from table_one cross join table_two;
COL_ONE COL_TWO COL_THREE COL_FOUR
---------- ---------- ---------- ----------
1 one 10 ten
1 one 20 twenty
1 one 5 five
2 two 10 ten
2 two 20 twenty
2 two 5 five
5 five 10 ten
5 five 20 twenty
5 five 5 five
已选择9行。
WANGZK>select * from table_one a cross join table_two b on a.col_one = b.col_three;
select * from table_one a cross join table_two b on a.col_one = b.col_three
*
第 1 行出现错误:
ORA-00933: SQL 命令未正确结束
交叉关联不允许有ON子句。