我需要并排放置两个不同的整数集合。这些值没有以任何方式链接在一起,它们只是数字,以后将用于插入。我已经尝试过了:
select A.COLUMN_VALUE as a, B.COLUMN_VALUE as b
from table(sys.ODCINUMBERLIST(123, 456)) A, table(sys.ODCINUMBERLIST(654, 321)) B;
哪个给出此结果-值A似乎重复:
+---+---+
|A |B |
+---+---+
|123|654|
|123|321|
|456|654|
|456|321|
+---+---+
我需要像这样:
+---+---+
|A |B |
+---+---+
|123|654|
|456|321|
+---+---+
有人知道我能做到这一点吗?
答案 0 :(得分:2)
您可以使用union all
或join
。假设您的长度相同:
select A.COLUMN_VALUE as a, B.COLUMN_VALUE as b
from (select a.column_value, rownum as rn
from table(sys.ODCINUMBERLIST(123, 456)) A
) a join
(select b.column_value, rownum as rn
form table(sys.ODCINUMBERLIST(654, 321))
) b
on a.rn = b.rn;
这将为每行分配一个行号,然后加入该行号。 join
假定两个列表的长度相同。如果没有,请使用full join
:
select A.COLUMN_VALUE as a, B.COLUMN_VALUE as b
from (select a.column_value, rownum as rn
from table(sys.ODCINUMBERLIST(123, 456)) A
) a full join
(select b.column_value, rownum as rn
form table(sys.ODCINUMBERLIST(654, 321))
) b
on a.rn = b.rn;