2014-01-29 65 views
0

我試圖執行以下查詢:使用一個SELECT語句中的甲骨文

SELECT pt.prod_desc"Description", 
(
CASE 
    WHEN pt.prod_level='2' 
THEN 'Product' 
WHEN pt.prod_level='4' 
THEN 'Sub-Product' 
WHEN pt.prod_level='5' 
THEN 'Service' 
ELSE 'N/A' 
END)"Level", prod_id"CKC ID", isactive"Active", updt_usr_sid"Last Updated By", 
updt_ts"LAst Updated Date", 
(CASE WHEN pt.prod_level='5' THEN parent_prod_id ELSE null END)"Parent Sub-Product CKC ID", 
(CASE WHEN Level='Service' THEN (Select prod_desc from dims_prod_type where prod_id= parent_prod_id) ELSE 'N/A' END) 
FROM dims_prod_type pt 
    ORDER BY prod_desc; 

我收到以下錯誤: 錯誤報告:

SQL Error: ORA-01788: CONNECT BY clause required in this query block 
01788. 00000 - "CONNECT BY clause required in this query block" 
*Cause:  
*Action: 

我修改我的查詢如下:

SELECT pt.prod_desc"Description", 
(
CASE 
    WHEN pt.prod_level='2' 
THEN 'Product' 
WHEN pt.prod_level='4' 
THEN 'Sub-Product' 
WHEN pt.prod_level='5' 
THEN 'Service' 
ELSE 'N/A' 
END)"Level", prod_id"CKC ID", isactive"Active", updt_usr_sid"Last Updated By", 
updt_ts"LAst Updated Date", 
(CASE WHEN pt.prod_level='5' THEN parent_prod_id ELSE null END)"Parent Sub-Product CKC ID", 
(CASE WHEN Level='Service' THEN (Select prod_desc from dims_prod_type where connect by prior prod_id=parent_prod_id) ELSE 'N/A' END) 
FROM dims_prod_type pt 
    ORDER BY prod_desc; 

仍然收到相同的錯誤。

+1

level關鍵字爲oracle保留,嘗試使用別名alias –

+1

使用別名dist在同一個表 –

+0

的兩個實例之間的苦苦掙扎。謝謝!如果我改變它的作品的別名。 – Ankit

回答

1

你已經犯了兩個錯誤的位置:

  1. 你稱爲列與level甲骨文保留關鍵字
  2. 你是指level列在它與的情況下創建相同的上下文/時:是列在該範圍內不作爲獨立列存在,並且不能在where/group by子句中引用,只是按子句排序