在我的WHERE子句中不允许使用OR的外连接运算符 - 错误:ORA-01719

时间:2014-03-06 19:48:57

标签: sql oracle where-clause

我需要检查底部的条件,但由于涉及的(+),我无法更改使用OR。我没有设置那部分,所以我不确定如何重新安排它。有人能告诉我我能做些什么才能让这些条件得以实现?

SELECT DISTINCT 
  t.tkt_sid,
  ts.tkt_sts_dsc,
  tp.prty_dsc,
  a.agt_cont_nbr,
  au_a.user_nm assigned_to,
  t.rcd_lst_user_ts 
FROM
  afp_asd.tkt t,
  afp_asd.tkt_prty tp,
  afp_asd.tkt_sts ts,
  afp_asd.tkt_type tt,
  afp_asd.tkt_log tl,
  afp_asd.agt a,
  afp_asd.asd_user au_a,
  afp_asd.asd_user au_c,
  afp_asd.asd_user au_l,
  afp_asd.asd_user au_log,
  afp_asd.prb_area pa1,
  afp_asd.prb_area pa2,
  afp_asd.prb_area pa3,
  afp_asd.mktg_org mo,
  afp_asd.src_sys ss,
  afp_asd.agt ofc,
  afp_asd.co c,
  afp_asd.agt_sts ast 
WHERE (
    t.prty_cd = tp.prty_cd 
    AND t.tkt_sts_cd = ts.tkt_sts_cd 
    AND t.tkt_type_cd = tt.tkt_type_cd 
    AND t.agt_sid = a.agt_sid 
    AND t.assigned_id = au_a.asd_user_id 
    AND t.rcd_crt_user_id = au_c.asd_user_id (+) 
    AND t.lst_updater_id = au_l.asd_user_id 
    AND t.tkt_sid = tl.tkt_sid 
    AND t.prb_area_sid = pa3.prb_area_sid 
    AND tl.rcd_crt_user_id = au_log.asd_user_id 
    AND pa3.prb_hier_sid = pa2.prb_area_sid (+) 
    AND pa2.prb_hier_sid = pa1.prb_area_sid (+) 
    AND a.mktg_org_cd = mo.mktg_org_cd 
    AND a.src_sys_cd = mo.src_sys_cd 
    AND a.src_sys_cd = ss.src_sys_cd 
    AND a.ofc_id = ofc.agt_cont_nbr (+) 
    AND a.src_sys_cd = ofc.src_sys_cd (+) 
    AND a.co_sid = c.co_sid (+) 
    AND a.agt_sts_cd = ast.agt_sts_cd 
    AND tl.rcd_lst_user_ts >= :b_start_date 
    AND t.user_grp_sid = :b_group_id
  ) 
  AND (
    (TKT_STS_DSC NOT LIKE 'Completed') 
    OR (
      tp.prty_dsc = 'High' 
      AND ts.tkt_sts_dsc = 'Pending' 
      AND t.rcd_lst_user_ts < SYSDATE- 2
    ) 
    OR (
      t.rcd_lst_user_ts < SYSDATE- 3 
      AND ts.tkt_sts_dsc = 'In Progress' 
      AND tp.prty_dsc = 'High'
    ) 
    OR (
      t.rcd_lst_user_ts < SYSDATE- 15 
      AND ts.tkt_sts_dsc = 'In Progress' 
      AND tp.prty_dsc = 'Medium'
    ) 
    OR (
      t.rcd_lst_user_ts < SYSDATE- 28 
      AND ts.tkt_sts_dsc = 'In Progress' 
      AND tp.prty_dsc = 'Low'
    ) 
    OR (
      t.rcd_lst_user_ts < SYSDATE- 7 
      AND ts.tkt_sts_dsc = 'Pending' 
      AND tp.prty_dsc = 'High'
    ) 
    OR (
      t.rcd_lst_user_ts < SYSDATE- 21 
      AND ts.tkt_sts_dsc = 'Pending' 
      AND tp.prty_dsc = 'Medium'
    ) 
    OR (
      t.rcd_lst_user_ts < SYSDATE- 43 
      AND ts.tkt_sts_dsc = 'Pending' 
      AND tp.prty_dsc = 'Low'
    )
  ) 
ORDER BY ASSIGNED_TO,
  PRTY_DSC 

1 个答案:

答案 0 :(得分:3)

不要使用旧的FROM TableA,TableB WHERE ...连接语法。只是不要。

相反,请单独写出您的联接:

FROM TableA
INNER JOIN TableB ON ...
LEFT JOIN TableC ON ...

这不仅仅是对旧语法的一般性咆哮:使用新的(我说“新”,但现在已超过20年),标准语法将< / strong>在这种情况下解决您的问题。