2014-02-11 79 views
1

我正在寫一個單元測試的方法用下面的SQLH2DB WITH子句

WITH temptab(
i__id , i__name, i__effective, i__expires, i__lefttag, i__righttag, 
hier_id, hier_dim_id, parent_item_id, parent_hier_id, parent_dim_id, 
ancestor, h__id, h__name, h__level, h__effective, h__expires, rec_lvl) 
AS ( 
    SELECT 
    item.id   as i__id,   
    item.name  as i__name,   
    item.effectivets as i__effective,   
    item.expirests  as i__expires,  
    item.lefttag  as i__lefttag,  
    item.righttag as i__righttag,  
    hier_id,  hier_dim_id,   
    parent_item_id,  
    parent_hier_id,  
    parent_dim_id,  1   as ancestor,  
    hier.id as h__id,  hier.name as h__name, 
    hier.level as h__level,  hier.effectivets as h__effective,  
    hier.expirests as h__expires,  1 as rec_lvl FROM metro.item item,  
    metro.hierarchy hier WHERE item.id = 'DI'  AND hier_id = '69'  AND hier_dim_id= '36' AND hier.id =item.hier_id 
) 
SELECT 
    i__id, i__name, i__effective, i__expires, i__lefttag, 
    i__righttag, hier_id, hier_dim_id, parent_item_id, 
    parent_hier_id, parent_dim_id, ancestor, 
    h__id, h__name, h__level, h__effective, h__expires 
FROM temptab 

該查詢返回空集,但我希望1列。

數據是正確的,因爲類似的簡單查詢沒有with子句工作正常。

我調查了這個問題,我發現
Sub Query with WITH-CLAUSE in H2DB 但該解決方案沒有幫助。

那麼,有沒有人知道H2支持子句?

提前感謝您的時間。

+0

H2 * *僅支持遞歸的CTE。它不**支持常規CTE –

回答

1

根據以下幾點:h2 database grammar

看起來像H2數據庫不支持WITH條款,除了對遞歸查詢的實驗性支持:h2 recursive queries

+1

它受支持,但僅用於遞歸查詢:http://www.h2database.com/html/advanced.html#recursive_queries –