Hi there,
We have started to put together a Oracle SQL report to identify all items within our environment which have greater than 5 versions; we want to be able to do this by specifying a folder and getting results for this folder and all subfolders. The below SQL is what we have come up with. In this instance dataid 42412 is the id of the folder we want the report to run against.
If we remove the last line "start with dataid = 42412 connect by nocycle prior dataid = parentid;" the report runs however doesn't allow us to specify a folder and instead returns results for entire environment. When we put this final line in to specify a folder the report runs for a very long time and appears to get stuck in a loop, sometimes it'll timeout before we stop it.
Any suggestions on what we're doing wrong?
CREATE OR REPLACE FUNCTION Folder_Path ( selid number ) return varchar2 AS
n integer;
pname varchar2(255);
pstring varchar2(32000);
cursor plist (id number) is
select name
from dtreecore
where dataid > 0 and level > 1
start with dataid = id
connect by abs(dataid) = prior abs(parentid)
order by level desc;
BEGIN
n := 0;
pstring := '';
open plist(selid);
LOOP
n := n + 1;
BEGIN
fetch plist into pname;
EXCEPTION
when value_error then return 'ERROR: Cannot find folder path.';
END;
exit when plist%NOTFOUND;
IF n = 1 THEN pstring := pname;
ELSE pstring := pstring || '/' || pname;
END IF;
END LOOP;
close plist;
return pstring;
END Folder_Path;
/
select
distinct RPAD(dtreecore.name,50, ' ') as "File Name",
(select RPAD (kuaf.name,30, ' ') from kuaf where kuaf.id=dtreecore.userid) as "Owner Username",
Folder_Path(dtreecore.dataid) as "Folder Path"
FROM dtreecore
where dtreecore.versionnum>5
start with dataid = 42412 connect by nocycle prior dataid = parentid;