如何在查询中取消嵌套嵌套表的集合?
我有一个过程,它接受类似于下面所示的parent_arr 的输入,作为通过 ODP.Net 来自应用程序层的输入。在该过程的第一步中,我将数组中的数据存储在全局临时表中,以便我可以使用设置逻辑而不是 pl/sql 循环继续执行以下几个步骤。只要数组只有一个parent_typ 成员,一切都很好。但是,当有多个成员时,我收到 ORA-01427,单行查询返回不止一行。下面的查询返回两个集合。我需要在单个 sql 语句中取消嵌套这两个集合,该语句将显示 child.name 和 child.value。那怎么办呢?
示例对象
create type child_typ is object( name varchar2(100), value number );
create type child_arr is table of dropme_child_typ;
create type parent_typ is object( pname varchar2(100), child dropme_child_arr );
create type parent_arr is table of dropme_parent_typ;
下面的查询将抛出 ORA-01427
select * from table(
select child
from table( parent_arr(
parent_typ( 'TEST1',
child_arr(
child_typ( 'C1', 1 ),
child_typ( 'C2', 2 ) ) ),
parent_typ( 'TEST2',
child_arr(
child_typ( 'C3', 3 ),
child_typ( 'C4', 4 ) ) ) ) ) );
该查询有效,但返回一列对象 child_arr
select child
from table( parent_arr(
parent_typ( 'TEST1',
child_arr(
child_typ( 'C1', 1 ),
child_typ( 'C2', 2 ) ) ),
parent_typ( 'TEST2',
child_arr(
child_typ( 'C3', 3 ),
child_typ( 'C4', 4 ) ) ) ) );
该查询失败,因为我无法访问“child”中的值
select child.name, child.value from
table( parent_arr(
parent_typ( 'TEST1',
child_arr(
child_typ( 'C1', 1 ),
child_typ( 'C2', 2 ) ) ),
parent_typ( 'TEST2',
child_arr(
child_typ( 'C3', 3 ),
child_typ( 'C4', 4 ) ) ) ) );
请告诉我有一种方法可以在不使用 pl/ 的情况下执行此操作sql 循环(这是迄今为止我能够成功的唯一方法)。速度至关重要。我尝试使用 forall 语句来循环 Parent_arr 的成员,但它会引发批量绑定错误。
I have a procedure that accepts an input similar to parent_arr shown below as input from the application layer via ODP.Net. In the first step of the procedure, I store data from the array in a global temporary table so I can proceed with several following steps using set logic rather than pl/sql loops. As long as the array has only a single member of parent_typ, everything is fine. However, when there is more than one member, I get ORA-01427, single row query returns more than one row. The query below returns two collections. I need to un-nest both collections in a single sql statement that will display child.name and child.value. How can that be done?
Sample objects
create type child_typ is object( name varchar2(100), value number );
create type child_arr is table of dropme_child_typ;
create type parent_typ is object( pname varchar2(100), child dropme_child_arr );
create type parent_arr is table of dropme_parent_typ;
The query below will throw ORA-01427
select * from table(
select child
from table( parent_arr(
parent_typ( 'TEST1',
child_arr(
child_typ( 'C1', 1 ),
child_typ( 'C2', 2 ) ) ),
parent_typ( 'TEST2',
child_arr(
child_typ( 'C3', 3 ),
child_typ( 'C4', 4 ) ) ) ) ) );
This query works, but returns a column of object child_arr
select child
from table( parent_arr(
parent_typ( 'TEST1',
child_arr(
child_typ( 'C1', 1 ),
child_typ( 'C2', 2 ) ) ),
parent_typ( 'TEST2',
child_arr(
child_typ( 'C3', 3 ),
child_typ( 'C4', 4 ) ) ) ) );
This query fails because I can't access values in "child"
select child.name, child.value from
table( parent_arr(
parent_typ( 'TEST1',
child_arr(
child_typ( 'C1', 1 ),
child_typ( 'C2', 2 ) ) ),
parent_typ( 'TEST2',
child_arr(
child_typ( 'C3', 3 ),
child_typ( 'C4', 4 ) ) ) ) );
Please tell me there is a way to do this without using a pl/sql loop (that is the only way I've been able to succeed so far). Speed is of the utmost importance. I tried using a forall statement to loop through memebers of the parent_arr, but it throws a bulk in-bind error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用横向联接来解除子对象的嵌套:
这是一种外连接形式,您可以将父对象与其子对象连接起来。
You could use a lateral join to unnest your child object:
It is a form of outer join where you join the parent with its children.