我正在尝试执行以下查询:
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;
仍然遇到同样的错误。
答案 0 :(得分:1)
你在这里犯了两个错误:
level
Oracle保留关键字level
列:该列不作为该范围中的独立列存在,并且不能在where / group by子句中引用,只是按条款排列