Oracle到Derby - ConnectBy并在Derby中以等效开头

时间:2014-06-04 07:16:04

标签: sql oracle derby db2-luw connect-by

以下Query1适用于Oracle。我希望在Derby中执行相同的功能。我得到了Query2,这是我要遵循的建议之一。但仍然是抛出Error1。请有人帮我摆脱这个。我该怎么办?

查询1:

Select f.folder_id, f.identifier

            From FOLDER f, STOREENT se
            Where f.type = 'AttributeFolder'
            And se.storeent_id = f.storeent_id 
            And se.identifier = 'Global_CAS'
            And f.identifier = 10051 
connect by prior f.folder_id = f.parentfolder_id
start with f.identifier = 'Categories Descriptors [Global.B2C.Sales]'

QUERY2:

with cte as (

select folder_id, f.identifier, cast(null as varchar(255)) parentfolder_id,

       0 as depth,
       se.identifier as se_identifier
       from folder f
       join storeent se on se.storeent_id = f.storeent_id
       where f.identifier = 'A'
    union all
    select f.folder_id, f.identifier, f.parentfolder_id,
       cte.depth + 1 as depth,
       se.identifier as se_identifier
    from folder f
    join storeent se on se.storeent_id = f.storeent_id
    join cte cte on f.parentfolder_id = cte.folder_id
)
Select parentfolder_id, folder_id, identifier, depth
from cte

ERROR1:

java.sql.SQLSyntaxErrorException: Syntax error: Encountered "with" at line 1, column 1

1 个答案:

答案 0 :(得分:3)

目前,德比不支持递归查询,请参阅https://issues.apache.org/jira/browse/DERBY-11(打开于2004年,2014年的最后评论)。所以很遗憾你不能在一个查询中执行此操作,你必须自己编写某种树遍历循环。