带Select语句的子查询在12C但不在11g上工作

时间:2017-11-07 19:12:24

标签: oracle oracle11g subquery

Select 
  c.id AS case_id, 
  c.id AS case_number, 
  tt.description as Target_Type, 
  coalesce(
    v_vendors.vendor_number, 
    vma.org_code, 
    TO_CHAR(sm.staff_member_id), 
    la.org_code, 
    oe.other_fns_number, 
    TO_CHAR(oe.other_id), 
    TO_CHAR(c_clients.client_id)
  ) as Target_Identifier, 
  coalesce(
    v_vendors.vendor_name, 
    vma.name, 
    s_wic_users.username, 
    la.name, 
    oe.other_name, 
    UPPER(
      c_clients.last_name || ', ' || c_clients.first_name
    )
  ) as Target_Name, 
  c.date_opened AS Open_Date, 
  c.date_closed AS Close_Date, 
  t.target_type_id, 
  t.target_id, 
  s.description AS Status, 
  case when aIosm.last_name is null then '' else UPPER(
    aIosm.last_name || ', ' || aIosm.first_name
  ) end Investigator, 
  case when aSosm.last_name is null then '' else UPPER(
    aSosm.last_name || ', ' || aSosm.first_name
  ) end Supervisor, 
  c.Notes AS Supervisor_Comments, 
  aI.Date_Assigned as Assign_Date, 
  ----subquery starts
  (
    select 
      lat.description 
    from 
      investigation_actions_taken iat 
      join investig_lu_action_type lat on iat.action_type_id = lat.id 
    where 
      iat.investigation_case_id = c.id 
      and iat.is_deleted <> 'T' 
    order by 
      iat.date_assessed desc, 
      iat.date_created desc OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
  ) AS Last_Action 
from 
  v_investigation_cases c 
  join investigation_target t on c.target_id = t.target_id 
  join v_lu_inv_status s on (
    case when date_closed <= TRUNC(sysdate) then 2 else case when date_opened > TRUNC(sysdate) then 2 else 1 end end
  ) = s.status_id 
  join investigation_target_type tt on t.target_type_id = tt.target_type_id
  ---left join starts  
  left join investigation_case_assignment aI on c.id = aI.investigation_case_id 
  and aI.date_roll_off is null 
  and aI.assignment_type = 'I' 
  left join o_staff_members aIosm on aI.staff_member_id = aIosm.staff_member_id 
  left join investigation_case_assignment Super on c.id = Super.investigation_case_id 
  and Super.date_roll_off is null 
  and Super.assignment_type = 'S' 
  left join o_staff_members aSosm on Super.staff_member_id = aSosm.staff_member_id 
  -----left join starts  
  left join v_vendors on t.vendor_id = v_vendors.id 
  left join o_organizational_units vma on t.vendor_management_area_id = vma.seq_id 
  left join c_clients on t.client_id = c_clients.client_id 
  left join o_staff_members sm on t.user_id = sm.staff_member_id 
  left join s_wic_users on sm.staff_member_id = s_wic_users.sm_staff_member_id 
  left join investigation_other_entity oe on t.non_wic_vendor_id = oe.other_id 
  left join o_organizational_units la on t.local_agency_id = la.seq_id 
  ---end of the query

1 个答案:

答案 0 :(得分:0)

这是一篇关于您可以在基于Kaushik Nayak的OFFEST FETCH在Oracle 12c中实现的目标的文章。

http://www.dba-oracle.com/t_offset_fet_first_rows_only.htm

我希望它可以帮助您将原始查询转换为11g。祝你好运。