WITH子句导致ORA-32044

时间:2014-10-09 01:20:55

标签: sql oracle recursive-query

我有一个在OBIEE报告中使用的查询,该报告在执行递归WITH查询时出错“ora-32044”。尝试在SQL中运行,它也在那里出错。任何人都可以查看查询并建议如何在没有WITH子句的情况下运行它。我已经看过但没有任何级别的示例,对于在查询中间使用了WITH的情况,如何在没有WITH子句的情况下重写它,因此不会出现ora-32044

   `SELECT 1 dummy, oh.order_number, ol.line_number, ol.shipment_number,
   oh.ordered_date, ot.NAME order_type, items.concatenated_segments item,
   items.description item_description
   ,bom.assembly_item 
   ,bom.component_item 
   ,bom.implementation_date 
   ,bom.disable_date as date_disabled 
   ,bom.component_item_description
   ,ol.flow_status_code line_status
   ,ol.ordered_quantity, 
    ol.shipped_quantity, 
    ol.unit_selling_price,
    ol.fulfilled_quantity, 
    ol.invoiced_quantity, 
    ol.cancelled_quantity,
    ol.schedule_ship_date, 
    ol.promise_date, 
    ol.actual_shipment_date,
    ol.request_date, 
    cust_acct.account_number customer_number,
    party.party_name customer, 
    ct.trx_number invoice_number,
    ctl.line_number inv_line_number, 
    ctl.extended_amount,
    ct.trx_date invoice_date, 
    ct.creation_date invoice_creation_date,
    wnd.NAME delivery_number, 
    wdd.released_status,
    hp2.party_name endcustomer,
    oh.attribute6 business_unit,
    TO_CHAR (ol.actual_shipment_date, 'MM/YY') shipped_month,
    TO_CHAR (ol.actual_shipment_date, '"Q"Q YY') shipped_qtr,
    TO_CHAR (ol.actual_shipment_date, 'YYYY') shipped_year,
    mc.segment1 product_group, mc.segment2 product_subgroup,
    items.attribute7 drive_capacity,
    items.attribute10 drive_form,
    items.attribute8 drive_speed,
    items.attribute6 drive_type,
    items.attribute12 AgileParttype,
    items.organization_id,
     case when dis.arithmetic_operator = 'NEWPRICE' then operand
     when dis.arithmetic_operator = '%' 
        then (ol.unit_selling_price* ol.ordered_quantity)*dis.operand/100.0
      else NVL((NVL (ol.pricing_quantity, 0) * NVL (dis.adjusted_amount, 0)),0) end 
         discount_amount
   FROM apps.oe_order_headers_all oh,
   apps.oe_order_lines_all ol,
   apps.wsh_new_deliveries wnd,
   apps.wsh_delivery_assignments wda,
   apps.wsh_delivery_details wdd,
   apps.ra_customer_trx_all ct,
   apps.ra_customer_trx_lines_all ctl,
   apps.oe_transaction_types_tl ot,
   (SELECT *
      FROM apps.mtl_system_items_vl
     WHERE organization_id = 84
     ) items,
   apps.hz_parties party,
   apps.hz_cust_accounts cust_acct,
   apps.hz_parties hp2,
   apps.hz_cust_accounts hca2,
   apps.mtl_item_categories mic,
   (SELECT *
      FROM apps.mtl_category_sets
     WHERE category_set_name = 'Inventory') ms,
   apps.mtl_categories mc,
     (select a.header_id, a.line_id ,a.list_header_id,a.creation_date,
   a.arithmetic_operator,a.unit_selling_price,a.operand,
   a.ordered_quantity, a.adjusted_amount
  from
  (select oh.header_id,     
  ol.line_id,pl.list_header_id,pl.creation_date,opa.arithmetic_operator, 
  ol.unit_selling_price,opa.operand,
  ol.ordered_quantity, opa.adjusted_amount
 from apps.oe_price_adjustments opa,
 apps.oe_order_lines_all ol,
 apps.oe_order_headers_all oh,
 apps.qp_list_headers_vl pl
 where oh.header_id = opa.header_id
 and ol.line_id = opa.line_id
 and opa.list_header_id = pl.list_header_id
 and opa.applied_flag = 'Y'
 AND opa.list_line_type_code = 'DIS') a,
 (select oh.header_id, ol.line_id,max(pl.creation_date) creation_date, min(operand)  
 operand
 from apps.oe_price_adjustments opa,
 apps.oe_order_lines_all ol,
 apps.oe_order_headers_all oh,
 apps.qp_list_headers_vl pl
 where oh.header_id = opa.header_id
 and ol.line_id = opa.line_id
 and opa.list_header_id = pl.list_header_id
 and opa.applied_flag = 'Y'
 AND opa.list_line_type_code = 'DIS'
 group by oh.header_id, ol.line_id) b
where 
a.header_id = b.header_id
and a.line_id = b.line_id
and a.creation_date = b.creation_date
and a.operand = b.operand ) dis 
,(
WITH recursiveBOM (parent_item_id,parent_item,parent_org_id,assembly_item_id,     
assembly_item,assembly_org_id,
component_item_id,component_item, component_item_description,implementation_date,   
disable_date)    AS
(
SELECT item.inventory_item_id parent_item_id
    ,item.segment1 parent_item
    ,item.organization_id parent_org_id
    ,bom.assembly_item_id
    ,msi.segment1 assembly_item
    ,bom.organization_id assembly_org_id
    ,bic.component_item_id
    ,msi2.segment1 component_item
    ,msi2.description component_item_description
    ,bic.implementation_date
    ,bic.disable_date
FROM apps.mtl_system_items_b item, apps.bom_bill_of_materials_v bom,   
apps.bom_inventory_components_v bic, apps.mtl_system_items msi, 
apps.mtl_system_items msi2
WHERE 1=1
AND bom.assembly_item_id   = item.inventory_item_id
AND bom.organization_id    = item.organization_id
AND bic.bill_sequence_id   = bom.common_bill_sequence_id
AND msi.inventory_item_id  = bom.assembly_item_id
AND msi.organization_id    = bom.organization_id
AND msi2.inventory_item_id = bic.component_item_id
AND msi2.organization_id   = msi.organization_id
AND bic.implementation_date IS NOT NULL
AND item.organization_id   = 84
AND item.inventory_item_id > 0
UNION ALL
 SELECT parent.parent_item_id
    ,parent.parent_item
    ,parent.parent_org_id
    ,bom.assembly_item_id
    ,msi.segment1 assembly_item
    ,bom.organization_id assembly_org_id
    ,bic.component_item_id
    ,msi2.segment1 component_item
    ,msi2.description component_item_description
    ,bic.implementation_date
    ,bic.disable_date
FROM recursiveBOM parent, apps.bom_bill_of_materials_v bom,    
apps.bom_inventory_components_v bic, apps.mtl_system_items msi, 
apps.mtl_system_items msi2
  WHERE 1=1
AND bic.bill_sequence_id   = bom.common_bill_sequence_id
AND msi.inventory_item_id  = bom.assembly_item_id
AND msi.organization_id    = bom.organization_id
AND msi2.inventory_item_id = bic.component_item_id
AND msi2.organization_id   = msi.organization_id
AND bic.implementation_date IS NOT NULL
AND bom.assembly_item_id   = parent.component_item_id
AND bom.organization_id    = parent.assembly_org_id
AND bom.organization_id    = 84
AND parent.assembly_org_id = 84
)
SELECT DISTINCT parent_item_id,parent_item,parent_org_id
    ,assembly_item_id
    ,assembly_item
    ,assembly_org_id
    ,component_item_id
    ,component_item
    ,component_item_description
    ,implementation_date
    ,disable_date  
FROM  recursiveBOM
) bom 
WHERE oh.header_id = ol.header_id
AND ol.line_id = wdd.source_line_id
AND wdd.source_code = 'OE'
AND wda.delivery_detail_id = wdd.delivery_detail_id
AND wda.delivery_id = wnd.delivery_id
AND ol.line_id = ctl.interface_line_attribute6(+)
AND ctl.customer_trx_id = ct.customer_trx_id(+)
AND oh.order_type_id = ot.transaction_type_id
AND ol.inventory_item_id = items.inventory_item_id
AND ol.sold_to_org_id = cust_acct.cust_account_id
AND cust_acct.party_id = party.party_id
AND oh.end_customer_id = hca2.cust_account_id(+)
AND hca2.party_id = hp2.party_id(+)
AND items.inventory_item_id = mic.inventory_item_id(+)
AND items.organization_id = mic.organization_id(+)
AND mic.category_id = mc.category_id(+)
AND mic.category_set_id = ms.category_set_id(+)
and ol.line_id = dis.line_id(+)
and ol.header_id = dis.header_id(+)      
AND bom.parent_item_id (+) = items.inventory_item_id 
AND bom.parent_org_id (+)  = items.organization_id ` 

0 个答案:

没有答案