1

I have a table like this:

dataid | parentid  |   name
----------------------------
   1   |     99    |  root 
----------------------------
   2   |     -1     | folder1 
----------------------------
   3   |     -1     | folder2 
----------------------------
   4   |    -1    |  file1 
----------------------------
   5   |     2     |  file2 

So rules are pretty weird. All of the items in a table are children of root. When folder is inside root it's parentid is negative, when file is inside root it's parentid is negative. But when file or folder is inside folder indise root it's parentid is positive.

So far I've written this query and it works with allways positive parents

SELECT name , CONNECT_BY_ISLEAF "IsLeaf",
   LEVEL, SYS_CONNECT_BY_PATH(dataid, '/') "Path"
   FROM TABLE
   WHERE 1=1
   START WITH dataid = 99
   CONNECT BY PRIOR dataid = abs(parentid);

So, I've managed to make it work using abs. BUT it takes too much time. Is therer another solution or maybe I should create an index...

ifuwannaride
  • 121
  • 3
  • 13

0 Answers0