Oracle to Derby - ConnectBy and Start With Equivalent in Derby

守給你的承諾、 提交于 2019-12-11 18:52:29

问题


The following Query1 is fine with Oracle. I want the same functionality to be carried out in Derby. I got the Query2, as one of the suggestion to be followed here. But still that is throwing the Error1. Please somebody help me out to get rid of this. What should I do?

Query1:

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:


Currently, derby does not support recursive queries, see https://issues.apache.org/jira/browse/DERBY-11 (openened in 2004, last comment in 2014). So unfortunately you cannot do this in a single query, you have to write some kind of tree traversal loop yourself.



来源:https://stackoverflow.com/questions/24031298/oracle-to-derby-connectby-and-start-with-equivalent-in-derby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!