有更好的方法吗?我正在尝试提取QC中特定文件夹下的所有内容
SELECT A.AL_FATHER_ID, A.AL_ITEM_ID, A.AL_DESCRIPTION as Folder
FROM All_LISTS A
where A.AL_DESCRIPTION=@folderName@
union
SELECT B.AL_FATHER_ID, B.AL_ITEM_ID, B.AL_DESCRIPTION as Folder
FROM All_LISTS B
where B.AL_FATHER_ID = (select A.AL_ITEM_ID from ALL_LISTS A where A.AL_DESCRIPTION=@folderName@)
union
SELECT B.AL_FATHER_ID, B.AL_ITEM_ID, B.AL_DESCRIPTION as Folder
FROM All_LISTS B
where B.AL_FATHER_ID in (select C.AL_ITEM_ID from ALL_LISTS C where C.AL_FATHER_ID= (select A.AL_ITEM_ID from ALL_LISTS A where A.AL_DESCRIPTION=@folderName@))
union
SELECT B.AL_FATHER_ID, B.AL_ITEM_ID, B.AL_DESCRIPTION as Folder
FROM All_LISTS B
where B.AL_FATHER_ID in (select D.AL_ITEM_ID from ALL_LISTS D where D.AL_FATHER_ID in (select C.AL_ITEM_ID from ALL_LISTS C where C.AL_FATHER_ID= (select A.AL_ITEM_ID from ALL_LISTS A where A.AL_DESCRIPTION=@folderName@)))
union
SELECT B.AL_FATHER_ID, B.AL_ITEM_ID, B.AL_DESCRIPTION as Folder
FROM All_LISTS B
where B.AL_FATHER_ID in (select E.AL_ITEM_ID from ALL_LISTS E where E.AL_FATHER_ID in(select D.AL_ITEM_ID from ALL_LISTS D where D.AL_FATHER_ID in (select C.AL_ITEM_ID from ALL_LISTS C where C.AL_FATHER_ID= (select A.AL_ITEM_ID from ALL_LISTS A where A.AL_DESCRIPTION=@folderName@))))
union
SELECT B.AL_FATHER_ID, B.AL_ITEM_ID, B.AL_DESCRIPTION as Folder
FROM All_LISTS B
where B.AL_FATHER_ID in (select F.AL_ITEM_ID from ALL_LISTS F where F.AL_FATHER_ID in (select E.AL_ITEM_ID from ALL_LISTS E where E.AL_FATHER_ID in(select D.AL_ITEM_ID from ALL_LISTS D where D.AL_FATHER_ID in (select C.AL_ITEM_ID from ALL_LISTS C where C.AL_FATHER_ID= (select A.AL_ITEM_ID from ALL_LISTS A where A.AL_DESCRIPTION=@folderName@)))))
感谢您的帮助
答案 0 :(得分:0)
如果你真的被SQL绑定了,那么你可能会好运,可以use Oracle 11gR2's recursive subquery factoring clause
,见http://technology.amis.nl/2009/09/01/oracle-rdbms-11gr2-goodbye-connect-by-or-the-end-of-hierarchical-querying-as-we-know-it/。
否则,您可能希望以迭代方式执行您现在所做的操作。这不会使更简单,但更通用(和可能更优雅)比您发布的解决方案,因为该解决方案仅限于固定数量的层次结构级别。