2015-05-18 200 views
-1

我怎樣才能改變給定的查詢:查詢轉換在Oracle

select 
    msi.attribute1 ref_no, 
    msi.description, 
    wdj.attribute10 order_id, 
    wdj.net_quantity, 
    '' Rec_date, 
    '' Qty, 
    '' packing_dated, 
    trunc(sysdate) issue_date, 
    hca.ACCOUNT_NUMBER||'-'||ooha.cust_po_number order_no, 
    ooha.order_number sale_order_no, 
    mci.attribute5 etching, 
    we.wip_entity_name, 
    weC.wip_entity_name "Relevant ASM job"  
    from wip_discrete_jobs wdj, 
    wip_entities we, 
    oe_order_headers_all ooha, 
    oe_order_lines_all oola, 
    mtl_customer_items mci, 
    mtl_system_items_b msi, 
    fnd_flex_values_vl ffvv, 
    hz_cust_accounts hca, 
    wip_discrete_jobs wdjC, 
    wip_entities weC 
    where 
    wdj.wip_entity_id = we.wip_entity_id 
    and ooha.header_id=wdj.attribute10 
    and ooha.header_id=oola.header_id 
    and oola.line_id=wdj.attribute9 
    and oola.ordered_item_id=mci.customer_item_id 
    and wdj.primary_item_id=msi.inventory_item_id 
    and msi.segment2 = ffvv.FLEX_VALUE 
    and mci.customer_id=hca.cust_account_id 
    AND wdjC.wip_entity_id = weC.wip_entity_id(+) 
    AND wdjC.attribute1(+) = we.wip_entity_name 
    and wdj.organization_id = msi.organization_id  
    and ffvv.FLEX_VALUE_SET_ID = '1014875' 
    and wdj.attribute10 = :order_id 

select 
    msi.attribute1 ref_no, 
    msi.description, 
    wdj.attribute10 order_id, 
    wdj.net_quantity, 
    '' Rec_date, 
    '' Qty, 
    '' packing_dated, 
    trunc(sysdate) issue_date, 
    hca.ACCOUNT_NUMBER||'-'||ooha.cust_po_number order_no, 
    ooha.order_number sale_order_no, 
    mci.attribute5 etching, 
    we.wip_entity_name  
    from wip_discrete_jobs wdj 
    join wip_entities we on wdj.wip_entity_id = we.wip_entity_id 
    join oe_order_headers_all ooha  on ooha.header_id=wdj.attribute10 
    join oe_order_lines_all oola on ooha.header_id=oola.header_id and oola.line_id=wdj.attribute9 
    join mtl_customer_items mci on oola.ordered_item_id=mci.customer_item_id 
    join mtl_system_items_b msi on wdj.primary_item_id=msi.inventory_item_id 
    join fnd_flex_values_vl ffvv on msi.segment2 = ffvv.FLEX_VALUE 
    join hz_cust_accounts hca on mci.customer_id=hca.cust_account_id 
    and wip_discrete_jobs wdjP inner join wip_entities weP on wdjP.WIP_ENTITY_ID=weP.WIP_ENTITY_ID  
    and wdj.organization_id = msi.organization_id  
    and ffvv.FLEX_VALUE_SET_ID = '1014875' 
    and wdj.attribute10 = :order_id 
+1

你顯然已經改變了查詢。那麼你的問題是什麼? –

+0

其在wip_discrete_jobs處給出錯誤wdjP內部連接wip_entities weP在wdjP.WIP_ENTITY_ID = weP.WIP_ENTITY_ID ORA-00920:無效的關係運算符 –

回答

1

您正試圖改變舊風格加入到ANSI連接,但查詢的這部分是不正確:

... 
join hz_cust_accounts hca on mci.customer_id=hca.cust_account_id 
         and wip_discrete_jobs wdjP 
inner join wip_entities weP on wdjP.WIP_ENTITY_ID=weP.WIP_ENTITY_ID  
and wdj.organization_id = msi.organization_id ... 

您沒有加入表wip_discrete_jobs,並且您正嘗試使用它的列。此舊語法: wdjC.wip_entity_id = weC.wip_entity_id(+)應更改爲left join,而不是inner join。 我想知道是否需要wip_discrete_jobs - select子句中此表中沒有列?

這裏是查詢,這應該是等同於你的第一次,但請仔細測試它 因爲沒有你的結構和數據訪問我沒有機會驗證:

select msi.attribute1 ref_no, msi.description, wdj.attribute10 order_id, 
    wdj.net_quantity, '' Rec_date, '' Qty, '' packing_dated, 
    trunc(sysdate) issue_date, 
    hca.ACCOUNT_NUMBER||'-'||ooha.cust_po_number order_no, 
    ooha.order_number sale_order_no, mci.attribute5 etching, 
    we.wip_entity_name, weC.wip_entity_name "Relevant ASM job"  
    from wip_discrete_jobs  wdj 
    join wip_entities   we on wdj.wip_entity_id  = we.wip_entity_id 
    join oe_order_headers_all ooha on ooha.header_id   = wdj.attribute10 
    join oe_order_lines_all oola on ooha.header_id   = oola.header_id 
            and oola.line_id   = wdj.attribute9 
    join mtl_customer_items mci on oola.ordered_item_id = mci.customer_item_id 
    join mtl_system_items_b msi on wdj.primary_item_id = msi.inventory_item_id 
            and wdj.organization_id = msi.organization_id 
    join fnd_flex_values_vl ffvv on msi.segment2   = ffvv.FLEX_VALUE 
            and ffvv.FLEX_VALUE_SET_ID = '1014875' 
    join hz_cust_accounts  hca on mci.customer_id  = hca.cust_account_id 
    left join wip_discrete_jobs wdjC on wdjC.attribute1  = we.wip_entity_name 
    left join wip_entities  weC on wdjC.wip_entity_id = weC.wip_entity_id 
    where 
    wdj.attribute10 = :order_id 
+0

解決了很多問題 –

+0

如果答案解決了問題,則應將其標記爲正確。 – Ollie