Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1370991
  • 博文数量: 205
  • 博客积分: 6732
  • 博客等级: 准将
  • 技术积分: 2835
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-04 17:59
文章分类

全部博文(205)

文章存档

2016年(1)

2015年(10)

2014年(1)

2013年(39)

2012年(23)

2011年(27)

2010年(21)

2009年(55)

2008年(28)

我的朋友

分类: Oracle

2009-08-19 19:28:23

select T1.SECTION_ID as sectionId,
       T1.SECTION_NAME as sectionName,
       T1.SECTION_PRINCIPAL as sectionPrincipal,
       T1.SECTION_MANAGER as sectionManager,
       T1.CHANNEL_ID as channelId,
       T1.CONTACT_PHONE as contactPhone,
       T1.LATN_ID as latnId,
       T1.SECTION_TYPE as sectionType,
       T1.CRT_DATE as crtDate,
       T1.MOD_DATE as modDate,
       T1.EMPEE_ID as empeeId,
       T1.STATE_G as state,
       T1.ENTITY_ID as entityId,
       T5.EMPEE_NAME as managerName,
       (select count(*)
          from TB_PTY_GRID_SECTION_REL T2,
               Tb_pty_inter_org T3,
               TB_PTY_CUST_551 T4
         where T1.SECTION_ID = T2.SECTION_ID
           and T2.GRID_ID = T3.inter_org_id
           and T3.inter_org_id = T4.REGION_ID
           and T3.eff_STATE = 'G01'
           and T3.inter_org_type_id = 1) as customerNum,
       (select count(*)
          from TB_PTY_GRID_SECTION_REL T2, Tb_pty_inter_org T3
         where T1.SECTION_ID = T2.SECTION_ID
           and T2.GRID_ID = T3.inter_org_id
           and T3.eff_STATE = 'G01'
           and inter_org_type_id = 1
           and T3.INTER_ORG_ID in
               (select t1.inter_org_id inOrgId1
                  from tb_pty_inter_org_rel t1,
                       tb_pty_inter_org t2,
                       tb_pty_inter_org_rel_type_ref t3,
                       tb_pty_inter_org_struc t4,
                       tb_pty_inter_org_rel t5
                 where t1.inter_org_id = t2.inter_org_id
                   and t1.inter_org_rel_type_id = t3.inter_org_rel_type_id
                   and t5.inter_org_rel_type_id = t3.inter_org_rel_type_id
                   and t1.INTER_ORG_STRUC_ID = t4.INTER_ORG_STRUC_ID(+)
                   and t1.index_code like t5.index_code || '%'
                   and t1.EFF_STATE = 'G01'
                   and t3.inter_org_rel_type_code = 'CHN_SALES'
                   and t4.inter_org_struc_code = 'REGION'
                   and (t5.inter_org_id = 60396035))) as griddingNum
  from TB_PTY_GRID_SECTIION T1, TB_PTY_EMPEE T5
 where 1 = 1
   and T1.SECTION_MANAGER = T5.empee_id
   and ((checksectionidisperm(T1.SECTION_ID,
                              'select t1.inter_org_id inOrgId1 from tb_pty_inter_org_rel t1, tb_pty_inter_org t2, tb_pty_inter_org_rel_type_ref t3, tb_pty_inter_org_struc t4, tb_pty_inter_org_rel t5 where t1.inter_org_id = t2.inter_org_id and t1.inter_org_rel_type_id =t3.inter_org_rel_type_id and t5.inter_org_rel_type_id =t3.inter_org_rel_type_id and t1.INTER_ORG_STRUC_ID = t4.INTER_ORG_STRUC_ID(+) and t1.index_code like t5.index_code||''%'' and t1.EFF_STATE=''G01'' and t3.inter_org_rel_type_code = ''CHN_SALES'' and t4.inter_org_struc_code = ''REGION'' and ( t5.inter_org_id = 60396035)') = 1) or
       T1.Empee_Id = 78 or T1.SECTION_MANAGER = 78)
   and T1.STATE_G = 'G01'
   and T1.LATN_ID = 551


注意对比

select T1.SECTION_ID as sectionId,
       T1.SECTION_NAME as sectionName,
       T1.SECTION_PRINCIPAL as sectionPrincipal,
       T1.SECTION_MANAGER as sectionManager,
       T1.CHANNEL_ID as channelId,
       T1.CONTACT_PHONE as contactPhone,
       T1.LATN_ID as latnId,
       T1.SECTION_TYPE as sectionType,
       T1.CRT_DATE as crtDate,
       T1.MOD_DATE as modDate,
       T1.EMPEE_ID as empeeId,
       T1.STATE_G as state,
       T1.ENTITY_ID as entityId,
       T5.EMPEE_NAME as managerName,
       (select count(*)
          from TB_PTY_GRID_SECTION_REL T2,
               Tb_pty_inter_org T3,
               TB_PTY_CUST_551 T4
         where T1.SECTION_ID = T2.SECTION_ID
           and T2.GRID_ID = T3.inter_org_id
           and T3.inter_org_id = T4.REGION_ID
           and T3.eff_STATE = 'G01'
           and T3.inter_org_type_id = 1) as customerNum,
       (select count(*)
          from TB_PTY_GRID_SECTION_REL T2, Tb_pty_inter_org T3
         where T1.SECTION_ID = T2.SECTION_ID
           and T2.GRID_ID = T3.inter_org_id
           and T3.eff_STATE = 'G01'
           and inter_org_type_id = 1
           and T3.INTER_ORG_ID in
               (select t1.inter_org_id inOrgId1
                  from tb_pty_inter_org_rel t1,
                       tb_pty_inter_org t2,
                       tb_pty_inter_org_rel_type_ref t3,
                       tb_pty_inter_org_struc t4,
                       tb_pty_inter_org_rel t5
                 where t1.inter_org_id = t2.inter_org_id
                   and t1.inter_org_rel_type_id = t3.inter_org_rel_type_id
                   and t5.inter_org_rel_type_id = t3.inter_org_rel_type_id
                   and t1.INTER_ORG_STRUC_ID = t4.INTER_ORG_STRUC_ID(+)
                   and t1.index_code like t5.index_code || '%'
                   and t1.EFF_STATE = 'G01'
                   and t3.inter_org_rel_type_code = 'CHN_SALES'
                   and t4.inter_org_struc_code = 'REGION'
                   and (t5.inter_org_id = 60396035))) as griddingNum
  from TB_PTY_GRID_SECTIION T1, TB_PTY_EMPEE T5
 where 1 = 1
   and T1.SECTION_MANAGER = T5.empee_id
   and ((not exists
        (select 1
            from TB_PTY_GRID_SECTION_REL w
           where w.section_id = T1.SECTION_ID
             and not exists
           (select t1.inter_org_id inOrgId1
                    from tb_pty_inter_org_rel t1,
                         tb_pty_inter_org t2,
                         tb_pty_inter_org_rel_type_ref t3,
                         tb_pty_inter_org_struc t4,
                         tb_pty_inter_org_rel t5
                   where t1.inter_org_id = t2.inter_org_id
                     and t1.inter_org_rel_type_id = t3.inter_org_rel_type_id
                     and t5.inter_org_rel_type_id = t3.inter_org_rel_type_id
                     and t1.INTER_ORG_STRUC_ID = t4.INTER_ORG_STRUC_ID(+)
                     and w.grid_id = t1.inter_org_id
                     and t1.index_code like t5.index_code || '%'
                     and t1.EFF_STATE = 'G01'
                     and t3.inter_org_rel_type_code = 'CHN_SALES'
                     and t4.inter_org_struc_code = 'REGION'
                     and (t5.inter_org_id = 60396035))) and exists
        (select 1
            from TB_PTY_GRID_SECTION_REL w
           where w.section_id = T1.SECTION_ID)) or T1.Empee_Id = 78 or
       T1.SECTION_MANAGER = 78)
   and T1.STATE_G = 'G01'
   and T1.LATN_ID = 551


用exists速度很快,用上面的那个超慢!
阅读(928) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~