如何使用Operator +在Left outer Join中使用Case语句?

时间:2015-05-28 13:00:57

标签: sql oracle oracle11g outer-join

查询:

select /*+ full(c)parallel(c,4) */ a.* 
    from   ioct_inv_item_all a, 
    (select udac_group_name, function_order , db_region, workflow_type, change_level
     from ioct_function_target 
     where udac_group_name = 'Banner' 
     and function_name = 'emptyParam' 
     and workflow_type = 'CHGFCLTR' 
     and ('emptyParam' = 'emptyParam' or ('CHGFCLTR' != 'NEWITM' AND change_level = 'emptyParam') or ('CHGFCLTR' = 'NEWITM' and change_level = 'Simple') )
     and sysdate between effective_from_date and effective_to_date ) b , item_ca c ,product_ca d,assignment_ca ac ,branches b
    where  a.udac_group_name = 'Banner'
    and a.workflow_type = 'CHGFCLTR' 
    and a.DB_REGION = b.db_region (+)
    and a.workflow_type = b.workflow_type (+)
    and a.udac_group_name = b.udac_group_name (+) 
    and a.change_level = b.change_level (+)
    and a.product_code = c.product_code(+)
    and a.product_issue_num = c.product_issue_num(+)
    and a.item_id = c.item_id(+)
    and a.customer_id = c.customer_id(+)
    and c.product_code = d.product_code(+)
    and c.product_issue_num = d.product_issue_num(+)
    and c.product_issue_year = d.product_issue_year(+)
    and c.customer_id = d.customer_id(+)
     and (case when c.contract_assignment_id IS NOT NULL
                            AND c.contract_assignment_id > 0
                        THEN c.contract_assignment_id
                        ELSE d.regular_assign_id
                            END) = ac.assignment_id(+)
    and    ('emptyParam' = 'emptyParam' OR ('CHGFCLTR' = 'NEWITM' AND a.eue_normal_ind = 'emptyParam') OR ('CHGFCLTR' != 'NEWITM' AND a.change_level = 'emptyParam') )
    and    (('emptyParam') IN ('emptyParam') OR a.region IN ('emptyParam')) 
    and ('emptyParam' = 'emptyParam' 
        OR (b.function_order is not null and a.assignee_group_seq = b.function_order) 
        OR (b.function_order is null and 'emptyParam' =  'emptyParam') 

错误:

  

错误:

     

ORA-01417:一个表可以外连接到最多一个其他表   01417. 00000 - “一张桌子最外面可以连接另一张桌子”      *原因:不允许a.b (+) = b.b and a.c (+) = c.c      *动作:检查这是否是你想要的,然后先加入b和c                  在一个视图中。       行错误:28列:20

在没有使用关键字LEFT OUTER JOIN的情况下,是否有任何机构建议做同样事情的替代方法,因为我不想更改已经写过的SQL查询的结构?

1 个答案:

答案 0 :(得分:0)

基本思路是你从一个驱动表开始,然后外连接到其他表。如果a是你的驾驶表,那么

select x
from   a,b,c
where  a.x = b.x(+)
  and  a.y = c.y(+)

是oracle在连接中期望的那种查询。

如果你真的想要外连接一个包含多个“驱动”表的表,你可以使用这样的语法,如错误描述中指出的那样

假设您要将“a”外部加入“b”和“c”

select *
from   a,
       (select *
        from   a,c
        where  c.y = a.y(+)
       )
where  b.x = a.x(+)
;