交叉加入到varray而不使用table()表达式
我正在尝试了解交叉加入Varray系列。
示例1:以下查询作品。它通过交叉连接到varray列中的元素 letter_array
,使用 table()
表达式:
with cte as (
select 1 as id, sys.odcivarchar2list('a', 'b') as letter_array from dual union all
select 2 as id, sys.odcivarchar2list('c', 'd', 'e', 'f') as letter_array from dual)
select
cte.id,
t.column_value
from
cte
cross join
table(letter_array) t
ID COLUMN_VALUE
----- -----------
1 a
1 b
2 c
2 d
2 e
2 f
它为每个< n 行生成 n 行代码> ID ( n 是 lette_array
中的元素数量的不同数量)。
示例2:在相关文章中,我们确定 table()
集合的关键字现在为 可选 。
因此,在下一个示例(使用略有不同的数据)中,我将使用 sys.odcivarchar2list('c','d','e',f')使用
table()
表达式:
with cte as (
select 1 as id from dual union all
select 2 as id from dual)
select
*
from
cte
cross join
sys.odcivarchar2list('c', 'd', 'e', 'f')
ID COLUMN_VALUE
----- ------------
1 c
1 d
1 e
1 f
2 c
2 d
2 e
2 f
也可以按预期工作。它为每个ID产生4行(4个是硬编码Varray表达式中的元素数)。
示例3:,我实际想要的是使用第一个示例中的数据,除了这次,在JOIN中使用varray 列,没有使用 table()
表达式:
with cte as (
select 1 as id, sys.odcivarchar2list('a', 'b') as letter_array from dual union all
select 2 as id, sys.odcivarchar2list('c', 'd', 'e', 'f') as letter_array from dual)
select
cte.id,
t.column_value
from
cte
cross join
letter_array t
错误:
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 11 Column: 10
问题:
如何在不使用table()表达式的情况下交叉连接到varray?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
交叉应用
:输出:
注意:使用遗产逗号加入,ANSI
交叉加入
and交叉加入横向
全部失败, Oracle 18c和21c,没有table
关键字,然后成功。请参阅下面的小提琴。注2:
表(...)
不是函数,它是db&lt;&gt;&gt; fiddle
Use
CROSS APPLY
:Which outputs:
Note: Using a legacy comma join, ANSI
CROSS JOIN
andCROSS JOIN LATERAL
all fail, in Oracle 18c and 21c, without theTABLE
keyword and succeed with it. See the fiddle below.Note 2:
TABLE(...)
is not a function, it is the syntax for a table collection expression (which wraps a collection expression).db<>fiddle here