线性化 Oracle 嵌套表
如何线性化嵌套表,该表本身也包含嵌套表(注意:内部表可能具有不同的大小)。假设我有以下类型声明:
CREATE OR REPLACE TYPE VECTOR
IS
TABLE OF NUMBER;
CREATE OR REPLACE TYPE TABLE_OF_VECTOR
IS
TABLE OF VECTOR;
以及以下 PL/SQL 片段:
DECLARE
number_table TABLE_OF_VECTOR;
result_vector VECTOR;
BEGIN
number_table := table_of_vector(vector(23, 4, 2222, 22222222),
vector(2, 1, 766, 2), vector(2, 1, 5));
END;
有没有一种方法可以线性化 number_table 并将其所有值作为一个连续的数字列表存储在 result_vector 中?我想结束:
result_vector == vector(23, 4, 2222, 22222222, 2, 1, 766, 2, 2, 1, 5)
How do I linearize a nested table, which in itself also contains nested tables (note: the inner tables could be of different size). Suppose I've got the following type declarations:
CREATE OR REPLACE TYPE VECTOR
IS
TABLE OF NUMBER;
CREATE OR REPLACE TYPE TABLE_OF_VECTOR
IS
TABLE OF VECTOR;
And the following snippet of PL/SQL:
DECLARE
number_table TABLE_OF_VECTOR;
result_vector VECTOR;
BEGIN
number_table := table_of_vector(vector(23, 4, 2222, 22222222),
vector(2, 1, 766, 2), vector(2, 1, 5));
END;
Is there a way I can linearize number_table and store all of its values in result_vector as one continuous list of numbers? I want to end up with:
result_vector == vector(23, 4, 2222, 22222222, 2, 1, 766, 2, 2, 1, 5)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实如此,但并不漂亮。
因此 table(...) 部分将 table_of_vector 视为“常规”表,其中有一列名为“COLUMN_VALUE”。然后,我们将其视为另一个我称为 B 的表。
SELECTed 表达式获取构成“A”表中的“B”表的所有单独数字,并将它们聚合到一个集合中(使用 COLLECT)。最后,我明确地将集合转换为 VECTOR 类型。
It does, but it isn't pretty.
So the table(...) a part treats the table_of_vector as a 'regular' table with a column with the name "COLUMN_VALUE". We then treat that as another table that I've called B.
The SELECTed expression takes all the individual numbers that made up the 'B' tables in the 'A' table and aggregates them into a collection (using COLLECT). Finally, I explicitly cast the collection as VECTOR type.