2013-09-24 1 views
0

다음 오류가 발생했습니다.ORA-00904 : WITH 절에 유효하지 않은 식별자 - 서브 쿼리 인수 분해

ORA-00904: "BKG_ITEM"."ITEM_NO": invalid identifier 
00904. 00000 - "%s: invalid identifier" 
*Cause:  
*Action: Error at Line: 11 Column: 60 

BKG_ITEM과 BKG는 내부 절에 의해 식별되지 않습니다. 내가 여기서 무엇을 놓치고 내가하려는 일을 할 수있는 방법이 있습니까? (WITH 절을 사용하여 쿼리를 최적화하려고합니다.)

select main_query.* 
     , RANK() OVER (ORDER BY booking_id, product_code, item_no) AS RNK 
     from 
      (select bkg_item.*, 
      (
      CASE (bkg_item.product_code) 
      WHEN ( 'TOU' ) THEN 
       ( 
       WITH rtb_dep_loc as (select departure_location from res_tour_booking rtb 
                where rtb.booking_id = bkg_item.booking_id 
                and rtb.item_no = bkg_item.item_no 
                and rtb.product_code = 'TOU' 
                and rownum = 1 
            )    
       select city.name name from city 
        inner join location lc on lc.city = city.code 
        inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location 
       union 
       select city.name name from city 
        inner join airport lc on lc.city = city.code 
        inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location 
       union 
       select city.name name from city 
        inner join supplier lc on lc.city = city.code 
        inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location 
      ) 
       else '' 
       end 
     ) as city 

    from 
     (select rb.* from res_booking rb where rb.booking_id > 0) bkg 
    inner join 
     (select rbi.* from res_booking_item rbi where rbi.booking_id > 0 and rbi.product_code not in ('OWA')) bkg_item 
    on bkg_item.booking_id = bkg.booking_id 
    )main_query; 

감사합니다.

답변

0
WITH 
bkg as (select rb.* from res_booking rb where rb.booking_id > 0), 
bkg_item as (select rbi.* from res_booking_item rbi where rbi.booking_id > 0 and rbi.product_code not in ('OWA')), 
select * 
     , RANK() OVER (ORDER BY booking_id, product_code, item_no) AS RNK 
     from 
      (select bkg_item.*, 
      (
      CASE (bkg_item.product_code) 
      WHEN ( 'TOU' ) THEN 
       ( 
       WITH rtb_dep_loc as (select departure_location from res_tour_booking rtb 
                where rtb.booking_id = bkg_item.booking_id 
                and rtb.item_no = bkg_item.item_no 
                and rtb.product_code = 'TOU' 
                and rownum = 1 
            )    
       select city.name name from city 
        inner join location lc on lc.city = city.code 
        inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location 
       union 
       select city.name name from city 
        inner join airport lc on lc.city = city.code 
        inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location 
       union 
       select city.name name from city 
        inner join supplier lc on lc.city = city.code 
        inner join rtb_dep_loc on lc.name = rtb_dep_loc.departure_location 
      ) 
       else '' 
       end 
     ) as city 
from bkg inner join bkg_item 
    on bkg_item.booking_id = bkg.booking_id; 
+0

답안에 약간의 구문 오류가 수정되어 실행되었지만 여전히 동일한 메시지가 표시됩니다. 그 이유를 설명 할 수 있다면 그 답을 찾을 수있을 것입니다. (또한 6 문자 편집 제한 때문에 main_query 별칭을 추가했습니다.) – Niroshan

+0

나는 당신의 대답 뒤에있는 이유를 의미했습니다. – Niroshan

관련 문제