PLSQL - 如何将给定值数组的值检索到集合中?
我有一个接受文件夹 ID 数组并需要返回文档 ID 列表的过程。文件夹与文档以一对多的关系关联——每个文件夹有许多文档。具体来说,有一个文档表,其中包含文件夹表的parent_folderid fk。
这就是我所拥有的:
PROCEDURE get_folder_documents_ (
paa_folderids_i IN gtyp_folderids_table
) IS
lnt_temp_docids &&MATTER_SCHEMA..docid_tab := &&MATTER_SCHEMA..docid_tab();
lv_current_table_size NUMBER := gnt_documentids.COUNT;
BEGIN
FOR i IN paa_folderids_i.FIRST .. paa_folderids_i.LAST
LOOP
SELECT documentid
BULK COLLECT INTO lnt_temp_docids
FROM t$documents
WHERE parent_folderid = paa_folderids_i(i);
FOR j IN 1 .. lnt_temp_docids.COUNT
LOOP
lv_current_table_size := lv_current_table_size + 1;
gnt_documentids.EXTEND(1);
gnt_documentids(lv_current_table_size) := lnt_temp_docids(j);
END LOOP;
END LOOP;
END get_folder_documents_;
有更好的方法吗?
I have a procedure that accepts an array of folder IDs and needs to return a list of document IDs. Folders are associated to documents in a one-to-many relationship--there are many documents for each folder. Specifically, there is a documents table which has a parent_folderid fk to the folders table.
This is what I have:
PROCEDURE get_folder_documents_ (
paa_folderids_i IN gtyp_folderids_table
) IS
lnt_temp_docids &&MATTER_SCHEMA..docid_tab := &&MATTER_SCHEMA..docid_tab();
lv_current_table_size NUMBER := gnt_documentids.COUNT;
BEGIN
FOR i IN paa_folderids_i.FIRST .. paa_folderids_i.LAST
LOOP
SELECT documentid
BULK COLLECT INTO lnt_temp_docids
FROM t$documents
WHERE parent_folderid = paa_folderids_i(i);
FOR j IN 1 .. lnt_temp_docids.COUNT
LOOP
lv_current_table_size := lv_current_table_size + 1;
gnt_documentids.EXTEND(1);
gnt_documentids(lv_current_table_size) := lnt_temp_docids(j);
END LOOP;
END LOOP;
END get_folder_documents_;
Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
gtyp_folderids_table
被声明为 SQL 类型(而不是 PL/SQL 类型),您可以通过table()
函数在 SQL 语句中使用它,如下所示:< strong>编辑
如果您想要 PL/SQL 答案,在 10g 中有一种更有效的方法 - 或者至少是一种需要更少打字的方法;)。
Oracle 引入了一些简洁的集合运算符,我们可以将它们与集合一起使用。以下示例使用 MULTISET UNION 将多个集合合并为一个...
了解有关 10g 中集合的更多信息。
If
gtyp_folderids_table
is declared as a SQL type (as opposed to a PL/SQL type) you could use it in a SQL statement via atable()
function like this:edit
If you want a PL/SQL answer, in 10g there is a more effective way - or at least an approach which requires less typing ;).
Oracle introduced some neat-o set operators which we can use with collections. The following example uses MULTISET UNION to munge several collections into one...
Find out more about collections in 10g.