码迷,mamicode.com
首页 > 数据库 > 详细

sql_delete_2017/11/1

时间:2017-11-01 21:32:07      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:.sh   怀柔区   证件   delete   朝阳区   ext   福建   cursor   修改   

create or replace procedure yuchuli_delete is
begin
    ----是否满足剔除条件    1hours

    declare
        ---1、地税状态(税务登记状态字段):证件失效企业、停业企业、注销、非正常注销企业
        cursor ds is
            select t.* ,qyghgx.GHDM,
                   qyghgx.GHMC,
                   qyghgx.GHLX,
                   qyghgx.ZHLX,
                   qyghgx.QYGHRS,
                   qyghgx.JHZT,
                   qyghgx.JHSJ,
                   qyghgx.SHSJ,
                   qyghgx.JFLCBL,
                   qyghgx.GHDM1,
                   qyghgx.BL1,
                   qyghgx.GHDM2,
                   qyghgx.BL2,
                   qyghgx.GHDM3,
                   qyghgx.BL3,
                   qyghgx.GHDM4,
                   qyghgx.BL4,
                   qyghgx.GHDM5,
                   qyghgx.BL5,
                   qyghgx.GHDM6,
                   qyghgx.BL6,
                   qyghgx.QYJC,
                   qyghgx.sffq
              from GH_QYXX t
              left join GH_QYGHGX qyghgx
                on t.qybm = qyghgx.qybm
              left join GH_ZD z
                on qyghgx.jhzt = z.zddm
             where (t.nsrztmc = ‘证件失效‘ or t.nsrztmc like ‘%停业%‘ or
                   t.nsrztmc = ‘注销‘ or t.nsrztmc like ‘%非正常%‘)
               and z.zdlx = ‘JHZT‘;
    
        ---2、是否是京外经营  28未建会-不应代收-京外经营
        ----2.1、所属街乡代码是否为空,不为空,则根据scjxdm来判断是否为京外经营
        cursor scjx is
            select t.* ,qyghgx.GHDM,
                   qyghgx.GHMC,
                   qyghgx.GHLX,
                   qyghgx.ZHLX,
                   qyghgx.QYGHRS,
                   qyghgx.JHZT,
                   qyghgx.JHSJ,
                   qyghgx.SHSJ,
                   qyghgx.JFLCBL,
                   qyghgx.GHDM1,
                   qyghgx.BL1,
                   qyghgx.GHDM2,
                   qyghgx.BL2,
                   qyghgx.GHDM3,
                   qyghgx.BL3,
                   qyghgx.GHDM4,
                   qyghgx.BL4,
                   qyghgx.GHDM5,
                   qyghgx.BL5,
                   qyghgx.GHDM6,
                   qyghgx.BL6,
                   qyghgx.QYJC,
                   qyghgx.sffq
              from GH_QYXX t
              left join GH_QYGHGX qyghgx
                on t.qybm = qyghgx.qybm
             where t.ISTCCONDITION = ‘0‘
               and substr(t.scjxdm, 0, 2) != ‘11‘;
        ---2.2、如果scjxdm是空的,则根据经营地址来判断是否为京外经营
        cursor scjxnull is
            select t.* ,qyghgx.GHDM,
                   qyghgx.GHMC,
                   qyghgx.GHLX,
                   qyghgx.ZHLX,
                   qyghgx.QYGHRS,
                   qyghgx.JHZT,
                   qyghgx.JHSJ,
                   qyghgx.SHSJ,
                   qyghgx.JFLCBL,
                   qyghgx.GHDM1,
                   qyghgx.BL1,
                   qyghgx.GHDM2,
                   qyghgx.BL2,
                   qyghgx.GHDM3,
                   qyghgx.BL3,
                   qyghgx.GHDM4,
                   qyghgx.BL4,
                   qyghgx.GHDM5,
                   qyghgx.BL5,
                   qyghgx.GHDM6,
                   qyghgx.BL6,
                   qyghgx.QYJC,
                   qyghgx.sffq
              from GH_QYXX t
              left join GH_QYGHGX qyghgx
                on t.qybm = qyghgx.qybm
             where t.ISTCCONDITION = ‘0‘
               and t.scjxdm is null;
    
        --3、空壳单位
        ---3.1已经建会的单位
        cursor jh is
            select qy.*
              from (select t.* ,qyghgx.GHDM,
                           qyghgx.GHMC,
                           qyghgx.GHLX,
                           qyghgx.ZHLX,
                           qyghgx.QYGHRS,
                           qyghgx.JHZT,
                           qyghgx.JHSJ,
                           qyghgx.SHSJ,
                           qyghgx.JFLCBL,
                           qyghgx.GHDM1,
                           qyghgx.BL1,
                           qyghgx.GHDM2,
                           qyghgx.BL2,
                           qyghgx.GHDM3,
                           qyghgx.BL3,
                           qyghgx.GHDM4,
                           qyghgx.BL4,
                           qyghgx.GHDM5,
                           qyghgx.BL5,
                           qyghgx.GHDM6,
                           qyghgx.BL6,
                           qyghgx.QYJC,
                           qyghgx.sffq
                      from GH_QYXX t
                      left join GH_QYGHGX qyghgx
                        on t.qybm = qyghgx.qybm
                     where t.ISTCCONDITION = ‘0‘
                       and qyghgx.jhzt in (‘0‘,
                                           ‘1‘,
                                           ‘2‘,
                                           ‘3‘,
                                           ‘4‘,
                                           ‘5‘,
                                           ‘6‘,
                                           ‘7‘,
                                           ‘8‘,
                                           ‘9‘,
                                           ‘10‘,
                                           ‘11‘,
                                           ‘12‘,
                                           ‘13‘,
                                           ‘14‘,
                                           ‘15‘,
                                           ‘16‘,
                                           ‘17‘)) qy
              left join (select qybm,
                                sum(zgrs) / count(zgrs) as zgrs,
                                sum(gzze) / count(gzze) as gzze
                           from gh_qygsgz
                          where (skssy = to_number(to_char(add_months(to_date(‘2017/08/01‘,
                                                                              ‘yyyy/mm/dd‘),
                                                                      -1),
                                                           ‘mm‘)) and
                                skssn = to_number(to_char(add_months(to_date(‘2017/08/01‘,
                                                                              ‘yyyy/mm/dd‘),
                                                                      -1),
                                                           ‘yyyy‘)))
                             or (skssy = to_number(to_char(add_months(to_date(‘2017/08/01‘,
                                                                              ‘yyyy/mm/dd‘),
                                                                      -2),
                                                           ‘mm‘)) and
                                skssn = to_number(to_char(add_months(to_date(‘2017/08/01‘,
                                                                              ‘yyyy/mm/dd‘),
                                                                      -2),
                                                           ‘yyyy‘)))
                             or (skssy = to_number(to_char(add_months(to_date(‘2017/08/01‘,
                                                                              ‘yyyy/mm/dd‘),
                                                                      -3),
                                                           ‘mm‘)) and
                                skssn = to_number(to_char(add_months(to_date(‘2017/08/01‘,
                                                                              ‘yyyy/mm/dd‘),
                                                                      -3),
                                                           ‘yyyy‘)))
                          group by qybm) gsgz
                on qy.qybm = gsgz.qybm
             where gsgz.zgrs < 3
                or gsgz.gzze = 0
                or gsgz.qybm is null;
    
        ----3.2未建会的单位
        cursor nojh is
            select qy.*, gsgz.zgrs, gsgz.gzze
              from (select t.* ,qyghgx.GHDM,
                           qyghgx.GHMC,
                           qyghgx.GHLX,
                           qyghgx.ZHLX,
                           qyghgx.QYGHRS,
                           qyghgx.JHZT,
                           qyghgx.JHSJ,
                           qyghgx.SHSJ,
                           qyghgx.JFLCBL,
                           qyghgx.GHDM1,
                           qyghgx.BL1,
                           qyghgx.GHDM2,
                           qyghgx.BL2,
                           qyghgx.GHDM3,
                           qyghgx.BL3,
                           qyghgx.GHDM4,
                           qyghgx.BL4,
                           qyghgx.GHDM5,
                           qyghgx.BL5,
                           qyghgx.GHDM6,
                           qyghgx.BL6,
                           qyghgx.QYJC,
                           qyghgx.sffq
                      from GH_QYXX t
                      left join GH_QYGHGX qyghgx
                        on t.qybm = qyghgx.qybm
                     where t.ISTCCONDITION = ‘0‘
                       and qyghgx.jhzt in (‘18‘,
                                           ‘19‘,
                                           ‘20‘,
                                           ‘21‘,
                                           ‘22‘,
                                           ‘23‘,
                                           ‘24‘,
                                           ‘25‘ , ‘28‘)) qy
              left join (select qybm, zgrs, gzze
                           from gh_qygsgz
                          where skssy = to_number(to_char(add_months(to_date(‘2017/08/01‘,
                                                                             ‘yyyy/mm/dd‘),
                                                                     -1),
                                                          ‘mm‘))
                            and skssn = to_number(to_char(add_months(to_date(‘2017/08/01‘,
                                                                             ‘yyyy/mm/dd‘),
                                                                     -1),
                                                          ‘yyyy‘))) gsgz
                on qy.qybm = gsgz.qybm
             where gsgz.zgrs < 3
                or gsgz.gzze = 0
                or gsgz.qybm is null;
    
    begin
    
        ---1、地税状态(税务登记状态字段):证件失效企业、停业企业、注销、非正常注销企业
        ---停业   6联合工会-不应代收-停业  15独立工会-不应代收-停业  23未建会-不应代收-停业
        ---注销  7联合工会-不应代收-注销  16独立工会-不应代收-注销   24未建会-不应代收-注销
        update GH_QYXX SET ISTCCONDITION = ‘0‘;
        for rc in ds loop
            update GH_QYXX SET ISTCCONDITION = ‘1‘ where qybm = rc.qybm;
            if (rc.nsrztmc = ‘证件失效‘ or rc.nsrztmc like ‘%停业%‘) then
                if (rc.jhzt in
                   (‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘)) then
                    ---联合工会
                    insert into GH_QYTC
                        (YWLSDM,
                         QYBM,
                         QYSQZT,
                         QYBQZT,
                         SFBL,
                         CZYYDM,
                         CZRYDM,
                         JHZT)
                    values
                        (SEQ_QYTC.NEXTVAL,
                         rc.qybm,
                         ‘1‘,
                         ‘1‘,
                         ‘0‘,
                         rc.nsrztmc,
                         ‘1‘,
                         rc.jhzt);
                    if (rc.jhzt != ‘6‘) then
                        ---修改建会状态
                        update gh_qyghgx
                           set jhzt = ‘6‘
                         where qybm = rc.qybm;
                        -----增加变更历史表数据
                        insert into GH_QYBG_LS
                            (QYTCID,
                             ID,
                             YWLSDM,
                             QYBM,
                             BGXXZ,
                             BGXJZ,
                             SPZT,
                             CZRYDM,
                             CZSJ,
                             BGXDM,
                             GHDM,
                             GHMC,
                             GHLX,
                             ZHLX,
                             QYGHRS,
                             JHZT,
                             JHSJ,
                             SHSJ,
                             JFLCBL,
                             GHDM1,
                             BL1,
                             GHDM2,
                             BL2,
                             GHDM3,
                             BL3,
                             GHDM4,
                             BL4,
                             GHDM5,
                             BL5,
                             GHDM6,
                             BL6,
                             QYJC,
                             DRRQ,
                             QYMC,
                             SJJYDZ,
                             LXR,
                             LXDH,
                             KHH,
                             KHZH,
                             KHMC,
                             JSJDM,
                             TYSHXYDM,
                             DJZCLXDM,
                             ZZJGDM,
                             JYDZ,
                             JYDZYB,
                             ZCDZ,
                             ZCDZYB,
                             JYDZLXDM,
                             SWJGZZJGDM,
                             SCJXDM,
                             NSRZTMC,
                             GJBZHYDM,
                             KYDJRQ,
                             SWDJLXMC,
                             SJQYMC,
                             SJJYDZYB,
                             QYZT,
                             QYFR,
                             JHH,
                             XEZFH,
                             GSRS,
                             SSGLYDM,
                             ISTC,
                             NSRSBH,
                             XGRQ,
                             SFFQ)
                        values
                            (SEQ_QYTC.Currval,
                             SEQ_YWLS.NEXTVAL,
                             SEQ_YWLS.NEXTVAL,
                             rc.QYBM,
                             ‘6‘,
                             rc.jhzt,
                             ‘0‘,
                             ‘预处理‘,
                             sysdate,
                             ‘jhzt‘,
                             rc.GHDM,
                             rc.GHMC,
                             rc.GHLX,
                             rc.ZHLX,
                             rc.QYGHRS,
                             rc.JHZT,
                             rc.JHSJ,
                             rc.SHSJ,
                             rc.JFLCBL,
                             rc.GHDM1,
                             rc.BL1,
                             rc.GHDM2,
                             rc.BL2,
                             rc.GHDM3,
                             rc.BL3,
                             rc.GHDM4,
                             rc.BL4,
                             rc.GHDM5,
                             rc.BL5,
                             rc.GHDM6,
                             rc.BL6,
                             rc.QYJC,
                             rc.DRRQ,
                             rc.QYMC,
                             rc.SJJYDZ,
                             rc.LXR,
                             rc.LXDH,
                             rc.KHH,
                             rc.KHZH,
                             rc.KHMC,
                             rc.JSJDM,
                             rc.TYSHXYDM,
                             rc.DJZCLXDM,
                             rc.ZZJGDM,
                             rc.JYDZ,
                             rc.JYDZYB,
                             rc.ZCDZ,
                             rc.ZCDZYB,
                             rc.JYDZLXDM,
                             rc.SWJGZZJGDM,
                             rc.SCJXDM,
                             rc.NSRZTMC,
                             rc.GJBZHYDM,
                             rc.KYDJRQ,
                             rc.SWDJLXMC,
                             rc.SJQYMC,
                             rc.SJJYDZYB,
                             rc.QYZT,
                             rc.QYFR,
                             rc.JHH,
                             rc.XEZFH,
                             rc.GSRS,
                             rc.SSGLYDM,
                             rc.ISTC,
                             rc.NSRSBH,
                             rc.XGRQ,
                             rc.SFFQ);
                    end if;
                elsif (rc.jhzt in
                      (‘9‘, ‘10‘, ‘11‘, ‘12‘, ‘13‘, ‘14‘, ‘15‘, ‘16‘, ‘17‘)) then
                    --独立工会
                    insert into GH_QYTC
                        (YWLSDM,
                         QYBM,
                         QYSQZT,
                         QYBQZT,
                         SFBL,
                         CZYYDM,
                         CZRYDM,
                         JHZT)
                    values
                        (SEQ_QYTC.NEXTVAL,
                         rc.qybm,
                         ‘1‘,
                         ‘1‘,
                         ‘0‘,
                         rc.nsrztmc,
                         ‘1‘,
                         rc.jhzt);
                    if (rc.jhzt != ‘15‘) then
                        ---修改建会状态
                        update gh_qyghgx
                           set jhzt = ‘15‘
                         where qybm = rc.qybm;
                        -----增加变更历史表数据
                        insert into GH_QYBG_LS
                            (QYTCID,
                             ID,
                             YWLSDM,
                             QYBM,
                             BGXXZ,
                             BGXJZ,
                             SPZT,
                             CZRYDM,
                             CZSJ,
                             BGXDM,
                             GHDM,
                             GHMC,
                             GHLX,
                             ZHLX,
                             QYGHRS,
                             JHZT,
                             JHSJ,
                             SHSJ,
                             JFLCBL,
                             GHDM1,
                             BL1,
                             GHDM2,
                             BL2,
                             GHDM3,
                             BL3,
                             GHDM4,
                             BL4,
                             GHDM5,
                             BL5,
                             GHDM6,
                             BL6,
                             QYJC,
                             DRRQ,
                             QYMC,
                             SJJYDZ,
                             LXR,
                             LXDH,
                             KHH,
                             KHZH,
                             KHMC,
                             JSJDM,
                             TYSHXYDM,
                             DJZCLXDM,
                             ZZJGDM,
                             JYDZ,
                             JYDZYB,
                             ZCDZ,
                             ZCDZYB,
                             JYDZLXDM,
                             SWJGZZJGDM,
                             SCJXDM,
                             NSRZTMC,
                             GJBZHYDM,
                             KYDJRQ,
                             SWDJLXMC,
                             SJQYMC,
                             SJJYDZYB,
                             QYZT,
                             QYFR,
                             JHH,
                             XEZFH,
                             GSRS,
                             SSGLYDM,
                             ISTC,
                             NSRSBH,
                             XGRQ,
                             SFFQ)
                        values
                            (SEQ_QYTC.Currval,
                             SEQ_YWLS.NEXTVAL,
                             SEQ_YWLS.NEXTVAL,
                             rc.QYBM,
                             ‘15‘,
                             rc.jhzt,
                             ‘0‘,
                             ‘预处理‘,
                             sysdate,
                             ‘jhzt‘,
                             rc.GHDM,
                             rc.GHMC,
                             rc.GHLX,
                             rc.ZHLX,
                             rc.QYGHRS,
                             rc.JHZT,
                             rc.JHSJ,
                             rc.SHSJ,
                             rc.JFLCBL,
                             rc.GHDM1,
                             rc.BL1,
                             rc.GHDM2,
                             rc.BL2,
                             rc.GHDM3,
                             rc.BL3,
                             rc.GHDM4,
                             rc.BL4,
                             rc.GHDM5,
                             rc.BL5,
                             rc.GHDM6,
                             rc.BL6,
                             rc.QYJC,
                             rc.DRRQ,
                             rc.QYMC,
                             rc.SJJYDZ,
                             rc.LXR,
                             rc.LXDH,
                             rc.KHH,
                             rc.KHZH,
                             rc.KHMC,
                             rc.JSJDM,
                             rc.TYSHXYDM,
                             rc.DJZCLXDM,
                             rc.ZZJGDM,
                             rc.JYDZ,
                             rc.JYDZYB,
                             rc.ZCDZ,
                             rc.ZCDZYB,
                             rc.JYDZLXDM,
                             rc.SWJGZZJGDM,
                             rc.SCJXDM,
                             rc.NSRZTMC,
                             rc.GJBZHYDM,
                             rc.KYDJRQ,
                             rc.SWDJLXMC,
                             rc.SJQYMC,
                             rc.SJJYDZYB,
                             rc.QYZT,
                             rc.QYFR,
                             rc.JHH,
                             rc.XEZFH,
                             rc.GSRS,
                             rc.SSGLYDM,
                             rc.ISTC,
                             rc.NSRSBH,
                             rc.XGRQ,
                             rc.SFFQ);
                    
                    end if;
                else
                    ---未建会和不建会
                    insert into GH_QYTC_LS
                        (YWLSDM,
                         QYBM,
                         QYSQZT,
                         QYBQZT,
                         SFBL,
                         CZYYDM,
                         CZRYDM,
                         JHZT)
                    values
                        (SEQ_QYTC.Nextval,
                         rc.qybm,
                         ‘1‘,
                         ‘1‘,
                         ‘1‘,
                         rc.nsrztmc,
                         ‘1‘,
                         rc.jhzt);
                    if (rc.jhzt != ‘23‘) then
                        ---修改建会状态
                        update gh_qyghgx
                           set jhzt = ‘23‘
                         where qybm = rc.qybm;
                        -----(未建会的)增加变更历史表数据
                        insert into GH_QYBG_LS
                            (QYTCID,
                             ID,
                             YWLSDM,
                             QYBM,
                             BGXXZ,
                             BGXJZ,
                             SPZT,
                             CZRYDM,
                             CZSJ,
                             BGXDM,
                             GHDM,
                             GHMC,
                             GHLX,
                             ZHLX,
                             QYGHRS,
                             JHZT,
                             JHSJ,
                             SHSJ,
                             JFLCBL,
                             GHDM1,
                             BL1,
                             GHDM2,
                             BL2,
                             GHDM3,
                             BL3,
                             GHDM4,
                             BL4,
                             GHDM5,
                             BL5,
                             GHDM6,
                             BL6,
                             QYJC,
                             DRRQ,
                             QYMC,
                             SJJYDZ,
                             LXR,
                             LXDH,
                             KHH,
                             KHZH,
                             KHMC,
                             JSJDM,
                             TYSHXYDM,
                             DJZCLXDM,
                             ZZJGDM,
                             JYDZ,
                             JYDZYB,
                             ZCDZ,
                             ZCDZYB,
                             JYDZLXDM,
                             SWJGZZJGDM,
                             SCJXDM,
                             NSRZTMC,
                             GJBZHYDM,
                             KYDJRQ,
                             SWDJLXMC,
                             SJQYMC,
                             SJJYDZYB,
                             QYZT,
                             QYFR,
                             JHH,
                             XEZFH,
                             GSRS,
                             SSGLYDM,
                             ISTC,
                             NSRSBH,
                             XGRQ,
                             SFFQ)
                        values
                            (SEQ_QYTC.CURRVAL,
                             SEQ_YWLS.NEXTVAL,
                             SEQ_YWLS.NEXTVAL,
                             rc.QYBM,
                             ‘23‘,
                             rc.jhzt,
                             ‘0‘,
                             ‘预处理‘,
                             sysdate,
                             ‘jhzt‘,
                             rc.GHDM,
                             rc.GHMC,
                             rc.GHLX,
                             rc.ZHLX,
                             rc.QYGHRS,
                             rc.JHZT,
                             rc.JHSJ,
                             rc.SHSJ,
                             rc.JFLCBL,
                             rc.GHDM1,
                             rc.BL1,
                             rc.GHDM2,
                             rc.BL2,
                             rc.GHDM3,
                             rc.BL3,
                             rc.GHDM4,
                             rc.BL4,
                             rc.GHDM5,
                             rc.BL5,
                             rc.GHDM6,
                             rc.BL6,
                             rc.QYJC,
                             rc.DRRQ,
                             rc.QYMC,
                             rc.SJJYDZ,
                             rc.LXR,
                             rc.LXDH,
                             rc.KHH,
                             rc.KHZH,
                             rc.KHMC,
                             rc.JSJDM,
                             rc.TYSHXYDM,
                             rc.DJZCLXDM,
                             rc.ZZJGDM,
                             rc.JYDZ,
                             rc.JYDZYB,
                             rc.ZCDZ,
                             rc.ZCDZYB,
                             rc.JYDZLXDM,
                             rc.SWJGZZJGDM,
                             rc.SCJXDM,
                             rc.NSRZTMC,
                             rc.GJBZHYDM,
                             rc.KYDJRQ,
                             rc.SWDJLXMC,
                             rc.SJQYMC,
                             rc.SJJYDZYB,
                             rc.QYZT,
                             rc.QYFR,
                             rc.JHH,
                             rc.XEZFH,
                             rc.GSRS,
                             rc.SSGLYDM,
                             rc.ISTC,
                             rc.NSRSBH,
                             rc.XGRQ,
                             rc.SFFQ);
                    end if;
                end if;
            else
                if (rc.jhzt in
                   (‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘)) then
                    ---联合工会
                    insert into GH_QYTC
                        (YWLSDM,
                         QYBM,
                         QYSQZT,
                         QYBQZT,
                         SFBL,
                         CZYYDM,
                         CZRYDM,
                         JHZT)
                    values
                        (SEQ_QYTC.NEXTVAL,
                         rc.qybm,
                         ‘1‘,
                         ‘1‘,
                         ‘0‘,
                         rc.nsrztmc,
                         ‘1‘,
                         rc.jhzt);
                    if (rc.jhzt != ‘7‘) then
                        ---修改建会状态
                        update gh_qyghgx
                           set jhzt = ‘7‘
                         where qybm = rc.qybm;
                        -----增加变更历史表数据
                        insert into GH_QYBG_LS
                            (QYTCID,
                             ID,
                             YWLSDM,
                             QYBM,
                             BGXXZ,
                             BGXJZ,
                             SPZT,
                             CZRYDM,
                             CZSJ,
                             BGXDM,
                             GHDM,
                             GHMC,
                             GHLX,
                             ZHLX,
                             QYGHRS,
                             JHZT,
                             JHSJ,
                             SHSJ,
                             JFLCBL,
                             GHDM1,
                             BL1,
                             GHDM2,
                             BL2,
                             GHDM3,
                             BL3,
                             GHDM4,
                             BL4,
                             GHDM5,
                             BL5,
                             GHDM6,
                             BL6,
                             QYJC,
                             DRRQ,
                             QYMC,
                             SJJYDZ,
                             LXR,
                             LXDH,
                             KHH,
                             KHZH,
                             KHMC,
                             JSJDM,
                             TYSHXYDM,
                             DJZCLXDM,
                             ZZJGDM,
                             JYDZ,
                             JYDZYB,
                             ZCDZ,
                             ZCDZYB,
                             JYDZLXDM,
                             SWJGZZJGDM,
                             SCJXDM,
                             NSRZTMC,
                             GJBZHYDM,
                             KYDJRQ,
                             SWDJLXMC,
                             SJQYMC,
                             SJJYDZYB,
                             QYZT,
                             QYFR,
                             JHH,
                             XEZFH,
                             GSRS,
                             SSGLYDM,
                             ISTC,
                             NSRSBH,
                             XGRQ,
                             SFFQ)
                        values
                            (SEQ_QYTC.Currval,
                             SEQ_YWLS.NEXTVAL,
                             SEQ_YWLS.NEXTVAL,
                             rc.QYBM,
                             ‘7‘,
                             rc.jhzt,
                             ‘0‘,
                             ‘预处理‘,
                             sysdate,
                             ‘jhzt‘,
                             rc.GHDM,
                             rc.GHMC,
                             rc.GHLX,
                             rc.ZHLX,
                             rc.QYGHRS,
                             rc.JHZT,
                             rc.JHSJ,
                             rc.SHSJ,
                             rc.JFLCBL,
                             rc.GHDM1,
                             rc.BL1,
                             rc.GHDM2,
                             rc.BL2,
                             rc.GHDM3,
                             rc.BL3,
                             rc.GHDM4,
                             rc.BL4,
                             rc.GHDM5,
                             rc.BL5,
                             rc.GHDM6,
                             rc.BL6,
                             rc.QYJC,
                             rc.DRRQ,
                             rc.QYMC,
                             rc.SJJYDZ,
                             rc.LXR,
                             rc.LXDH,
                             rc.KHH,
                             rc.KHZH,
                             rc.KHMC,
                             rc.JSJDM,
                             rc.TYSHXYDM,
                             rc.DJZCLXDM,
                             rc.ZZJGDM,
                             rc.JYDZ,
                             rc.JYDZYB,
                             rc.ZCDZ,
                             rc.ZCDZYB,
                             rc.JYDZLXDM,
                             rc.SWJGZZJGDM,
                             rc.SCJXDM,
                             rc.NSRZTMC,
                             rc.GJBZHYDM,
                             rc.KYDJRQ,
                             rc.SWDJLXMC,
                             rc.SJQYMC,
                             rc.SJJYDZYB,
                             rc.QYZT,
                             rc.QYFR,
                             rc.JHH,
                             rc.XEZFH,
                             rc.GSRS,
                             rc.SSGLYDM,
                             rc.ISTC,
                             rc.NSRSBH,
                             rc.XGRQ,
                             rc.SFFQ);
                    end if;
                elsif (rc.jhzt in
                      (‘9‘, ‘10‘, ‘11‘, ‘12‘, ‘13‘, ‘14‘, ‘15‘, ‘16‘, ‘17‘)) then
                    --独立工会
                    insert into GH_QYTC
                        (YWLSDM,
                         QYBM,
                         QYSQZT,
                         QYBQZT,
                         SFBL,
                         CZYYDM,
                         CZRYDM,
                         JHZT)
                    values
                        (SEQ_QYTC.NEXTVAL,
                         rc.qybm,
                         ‘1‘,
                         ‘1‘,
                         ‘0‘,
                         rc.nsrztmc,
                         ‘1‘,
                         rc.jhzt);
                    if (rc.jhzt != ‘16‘) then
                        ---修改建会状态
                        update gh_qyghgx
                           set jhzt = ‘16‘
                         where qybm = rc.qybm;
                        -----增加变更历史表数据
                        insert into GH_QYBG_LS
                            (QYTCID,
                             ID,
                             YWLSDM,
                             QYBM,
                             BGXXZ,
                             BGXJZ,
                             SPZT,
                             CZRYDM,
                             CZSJ,
                             BGXDM,
                             GHDM,
                             GHMC,
                             GHLX,
                             ZHLX,
                             QYGHRS,
                             JHZT,
                             JHSJ,
                             SHSJ,
                             JFLCBL,
                             GHDM1,
                             BL1,
                             GHDM2,
                             BL2,
                             GHDM3,
                             BL3,
                             GHDM4,
                             BL4,
                             GHDM5,
                             BL5,
                             GHDM6,
                             BL6,
                             QYJC,
                             DRRQ,
                             QYMC,
                             SJJYDZ,
                             LXR,
                             LXDH,
                             KHH,
                             KHZH,
                             KHMC,
                             JSJDM,
                             TYSHXYDM,
                             DJZCLXDM,
                             ZZJGDM,
                             JYDZ,
                             JYDZYB,
                             ZCDZ,
                             ZCDZYB,
                             JYDZLXDM,
                             SWJGZZJGDM,
                             SCJXDM,
                             NSRZTMC,
                             GJBZHYDM,
                             KYDJRQ,
                             SWDJLXMC,
                             SJQYMC,
                             SJJYDZYB,
                             QYZT,
                             QYFR,
                             JHH,
                             XEZFH,
                             GSRS,
                             SSGLYDM,
                             ISTC,
                             NSRSBH,
                             XGRQ,
                             SFFQ)
                        values
                            (SEQ_QYTC.Currval,
                             SEQ_YWLS.NEXTVAL,
                             SEQ_YWLS.NEXTVAL,
                             rc.QYBM,
                             ‘16‘,
                             rc.jhzt,
                             ‘0‘,
                             ‘预处理‘,
                             sysdate,
                             ‘jhzt‘,
                             rc.GHDM,
                             rc.GHMC,
                             rc.GHLX,
                             rc.ZHLX,
                             rc.QYGHRS,
                             rc.JHZT,
                             rc.JHSJ,
                             rc.SHSJ,
                             rc.JFLCBL,
                             rc.GHDM1,
                             rc.BL1,
                             rc.GHDM2,
                             rc.BL2,
                             rc.GHDM3,
                             rc.BL3,
                             rc.GHDM4,
                             rc.BL4,
                             rc.GHDM5,
                             rc.BL5,
                             rc.GHDM6,
                             rc.BL6,
                             rc.QYJC,
                             rc.DRRQ,
                             rc.QYMC,
                             rc.SJJYDZ,
                             rc.LXR,
                             rc.LXDH,
                             rc.KHH,
                             rc.KHZH,
                             rc.KHMC,
                             rc.JSJDM,
                             rc.TYSHXYDM,
                             rc.DJZCLXDM,
                             rc.ZZJGDM,
                             rc.JYDZ,
                             rc.JYDZYB,
                             rc.ZCDZ,
                             rc.ZCDZYB,
                             rc.JYDZLXDM,
                             rc.SWJGZZJGDM,
                             rc.SCJXDM,
                             rc.NSRZTMC,
                             rc.GJBZHYDM,
                             rc.KYDJRQ,
                             rc.SWDJLXMC,
                             rc.SJQYMC,
                             rc.SJJYDZYB,
                             rc.QYZT,
                             rc.QYFR,
                             rc.JHH,
                             rc.XEZFH,
                             rc.GSRS,
                             rc.SSGLYDM,
                             rc.ISTC,
                             rc.NSRSBH,
                             rc.XGRQ,
                             rc.SFFQ);
                    end if;
                else
                    ---未建会和不建会
                    insert into GH_QYTC_LS
                        (YWLSDM,
                         QYBM,
                         QYSQZT,
                         QYBQZT,
                         SFBL,
                         CZYYDM,
                         CZRYDM,
                         JHZT)
                    values
                        (SEQ_QYTC.Nextval,
                         rc.qybm,
                         ‘1‘,
                         ‘1‘,
                         ‘1‘,
                         rc.nsrztmc,
                         ‘1‘,
                         rc.jhzt);
                    if (rc.jhzt != ‘24‘) then
                        ---修改建会状态
                        update gh_qyghgx
                           set jhzt = ‘24‘
                         where qybm = rc.qybm;
                        -----(未建会的)增加变更历史表数据
                        insert into GH_QYBG_LS
                            (QYTCID,
                             ID,
                             YWLSDM,
                             QYBM,
                             BGXXZ,
                             BGXJZ,
                             SPZT,
                             CZRYDM,
                             CZSJ,
                             BGXDM,
                             GHDM,
                             GHMC,
                             GHLX,
                             ZHLX,
                             QYGHRS,
                             JHZT,
                             JHSJ,
                             SHSJ,
                             JFLCBL,
                             GHDM1,
                             BL1,
                             GHDM2,
                             BL2,
                             GHDM3,
                             BL3,
                             GHDM4,
                             BL4,
                             GHDM5,
                             BL5,
                             GHDM6,
                             BL6,
                             QYJC,
                             DRRQ,
                             QYMC,
                             SJJYDZ,
                             LXR,
                             LXDH,
                             KHH,
                             KHZH,
                             KHMC,
                             JSJDM,
                             TYSHXYDM,
                             DJZCLXDM,
                             ZZJGDM,
                             JYDZ,
                             JYDZYB,
                             ZCDZ,
                             ZCDZYB,
                             JYDZLXDM,
                             SWJGZZJGDM,
                             SCJXDM,
                             NSRZTMC,
                             GJBZHYDM,
                             KYDJRQ,
                             SWDJLXMC,
                             SJQYMC,
                             SJJYDZYB,
                             QYZT,
                             QYFR,
                             JHH,
                             XEZFH,
                             GSRS,
                             SSGLYDM,
                             ISTC,
                             NSRSBH,
                             XGRQ,
                             SFFQ)
                        values
                            (SEQ_QYTC.CURRVAL,
                             SEQ_YWLS.NEXTVAL,
                             SEQ_YWLS.NEXTVAL,
                             rc.QYBM,
                             ‘24‘,
                             rc.jhzt,
                             ‘0‘,
                             ‘预处理‘,
                             sysdate,
                             ‘jhzt‘,
                             rc.GHDM,
                             rc.GHMC,
                             rc.GHLX,
                             rc.ZHLX,
                             rc.QYGHRS,
                             rc.JHZT,
                             rc.JHSJ,
                             rc.SHSJ,
                             rc.JFLCBL,
                             rc.GHDM1,
                             rc.BL1,
                             rc.GHDM2,
                             rc.BL2,
                             rc.GHDM3,
                             rc.BL3,
                             rc.GHDM4,
                             rc.BL4,
                             rc.GHDM5,
                             rc.BL5,
                             rc.GHDM6,
                             rc.BL6,
                             rc.QYJC,
                             rc.DRRQ,
                             rc.QYMC,
                             rc.SJJYDZ,
                             rc.LXR,
                             rc.LXDH,
                             rc.KHH,
                             rc.KHZH,
                             rc.KHMC,
                             rc.JSJDM,
                             rc.TYSHXYDM,
                             rc.DJZCLXDM,
                             rc.ZZJGDM,
                             rc.JYDZ,
                             rc.JYDZYB,
                             rc.ZCDZ,
                             rc.ZCDZYB,
                             rc.JYDZLXDM,
                             rc.SWJGZZJGDM,
                             rc.SCJXDM,
                             rc.NSRZTMC,
                             rc.GJBZHYDM,
                             rc.KYDJRQ,
                             rc.SWDJLXMC,
                             rc.SJQYMC,
                             rc.SJJYDZYB,
                             rc.QYZT,
                             rc.QYFR,
                             rc.JHH,
                             rc.XEZFH,
                             rc.GSRS,
                             rc.SSGLYDM,
                             rc.ISTC,
                             rc.NSRSBH,
                             rc.XGRQ,
                             rc.SFFQ);
                    end if;
                end if;
            end if;
        end loop;
        insert into YUCHULI_MARK values (SYS_GUID(), ‘地税状态‘, sysdate);
        commit;
        ---2、是否是京外经营  28未建会-不应代收-京外经营
        ----2.1、所属街乡代码是否为空,不为空,则根据scjxdm来判断是否为京外经营
        for rc in scjx loop
            update GH_QYXX SET ISTCCONDITION = ‘1‘ where qybm = rc.qybm;
            ---增加到剔除表中
            if (rc.jhzt in (‘0‘,
                            ‘1‘,
                            ‘2‘,
                            ‘3‘,
                            ‘4‘,
                            ‘5‘,
                            ‘6‘,
                            ‘7‘,
                            ‘8‘,
                            ‘9‘,
                            ‘10‘,
                            ‘11‘,
                            ‘12‘,
                            ‘13‘,
                            ‘14‘,
                            ‘15‘,
                            ‘16‘,
                            ‘17‘)) then
                insert into GH_QYTC
                    (YWLSDM,
                     QYBM,
                     QYSQZT,
                     QYBQZT,
                     SFBL,
                     CZYYDM,
                     CZRYDM,
                     JHZT)
                values
                    (SEQ_QYTC.NEXTVAL,
                     rc.qybm,
                     ‘1‘,
                     ‘1‘,
                     ‘0‘,
                     ‘京外经营‘,
                     ‘1‘,
                     rc.jhzt);
                update gh_qyghgx set jhzt = ‘24‘ where qybm = rc.qybm;
                -----增加变更历史表数据
                insert into GH_QYBG_LS
                    (QYTCID,
                     ID,
                     YWLSDM,
                     QYBM,
                     BGXXZ,
                     BGXJZ,
                     SPZT,
                     CZRYDM,
                     CZSJ,
                     BGXDM,
                     GHDM,
                     GHMC,
                     GHLX,
                     ZHLX,
                     QYGHRS,
                     JHZT,
                     JHSJ,
                     SHSJ,
                     JFLCBL,
                     GHDM1,
                     BL1,
                     GHDM2,
                     BL2,
                     GHDM3,
                     BL3,
                     GHDM4,
                     BL4,
                     GHDM5,
                     BL5,
                     GHDM6,
                     BL6,
                     QYJC,
                     DRRQ,
                     QYMC,
                     SJJYDZ,
                     LXR,
                     LXDH,
                     KHH,
                     KHZH,
                     KHMC,
                     JSJDM,
                     TYSHXYDM,
                     DJZCLXDM,
                     ZZJGDM,
                     JYDZ,
                     JYDZYB,
                     ZCDZ,
                     ZCDZYB,
                     JYDZLXDM,
                     SWJGZZJGDM,
                     SCJXDM,
                     NSRZTMC,
                     GJBZHYDM,
                     KYDJRQ,
                     SWDJLXMC,
                     SJQYMC,
                     SJJYDZYB,
                     QYZT,
                     QYFR,
                     JHH,
                     XEZFH,
                     GSRS,
                     SSGLYDM,
                     ISTC,
                     NSRSBH,
                     XGRQ,
                     SFFQ)
                values
                    (SEQ_QYTC.Currval,
                     SEQ_YWLS.NEXTVAL,
                     SEQ_YWLS.NEXTVAL,
                     rc.QYBM,
                     ‘24‘,
                     rc.jhzt,
                     ‘0‘,
                     ‘预处理‘,
                     sysdate,
                     ‘jhzt‘,
                     rc.GHDM,
                     rc.GHMC,
                     rc.GHLX,
                     rc.ZHLX,
                     rc.QYGHRS,
                     rc.JHZT,
                     rc.JHSJ,
                     rc.SHSJ,
                     rc.JFLCBL,
                     rc.GHDM1,
                     rc.BL1,
                     rc.GHDM2,
                     rc.BL2,
                     rc.GHDM3,
                     rc.BL3,
                     rc.GHDM4,
                     rc.BL4,
                     rc.GHDM5,
                     rc.BL5,
                     rc.GHDM6,
                     rc.BL6,
                     rc.QYJC,
                     rc.DRRQ,
                     rc.QYMC,
                     rc.SJJYDZ,
                     rc.LXR,
                     rc.LXDH,
                     rc.KHH,
                     rc.KHZH,
                     rc.KHMC,
                     rc.JSJDM,
                     rc.TYSHXYDM,
                     rc.DJZCLXDM,
                     rc.ZZJGDM,
                     rc.JYDZ,
                     rc.JYDZYB,
                     rc.ZCDZ,
                     rc.ZCDZYB,
                     rc.JYDZLXDM,
                     rc.SWJGZZJGDM,
                     rc.SCJXDM,
                     rc.NSRZTMC,
                     rc.GJBZHYDM,
                     rc.KYDJRQ,
                     rc.SWDJLXMC,
                     rc.SJQYMC,
                     rc.SJJYDZYB,
                     rc.QYZT,
                     rc.QYFR,
                     rc.JHH,
                     rc.XEZFH,
                     rc.GSRS,
                     rc.SSGLYDM,
                     rc.ISTC,
                     rc.NSRSBH,
                     rc.XGRQ,
                     rc.SFFQ);
            
            else
                insert into GH_QYTC_LS
                    (YWLSDM,
                     QYBM,
                     QYSQZT,
                     QYBQZT,
                     SFBL,
                     CZYYDM,
                     CZRYDM,
                     JHZT)
                values
                    (SEQ_QYTC.Nextval,
                     rc.qybm,
                     ‘1‘,
                     ‘1‘,
                     ‘1‘,
                     ‘京外经营‘,
                     ‘1‘,
                     rc.jhzt);
                if (rc.jhzt != ‘28‘) then
                    ---修改建会状态
                    update gh_qyghgx set jhzt = ‘28‘ where qybm = rc.qybm;
                    -----(未建会的)增加变更历史表数据
                    insert into GH_QYBG_LS
                        (QYTCID,
                         ID,
                         YWLSDM,
                         QYBM,
                         BGXXZ,
                         BGXJZ,
                         SPZT,
                         CZRYDM,
                         CZSJ,
                         BGXDM,
                         GHDM,
                         GHMC,
                         GHLX,
                         ZHLX,
                         QYGHRS,
                         JHZT,
                         JHSJ,
                         SHSJ,
                         JFLCBL,
                         GHDM1,
                         BL1,
                         GHDM2,
                         BL2,
                         GHDM3,
                         BL3,
                         GHDM4,
                         BL4,
                         GHDM5,
                         BL5,
                         GHDM6,
                         BL6,
                         QYJC,
                         DRRQ,
                         QYMC,
                         SJJYDZ,
                         LXR,
                         LXDH,
                         KHH,
                         KHZH,
                         KHMC,
                         JSJDM,
                         TYSHXYDM,
                         DJZCLXDM,
                         ZZJGDM,
                         JYDZ,
                         JYDZYB,
                         ZCDZ,
                         ZCDZYB,
                         JYDZLXDM,
                         SWJGZZJGDM,
                         SCJXDM,
                         NSRZTMC,
                         GJBZHYDM,
                         KYDJRQ,
                         SWDJLXMC,
                         SJQYMC,
                         SJJYDZYB,
                         QYZT,
                         QYFR,
                         JHH,
                         XEZFH,
                         GSRS,
                         SSGLYDM,
                         ISTC,
                         NSRSBH,
                         XGRQ,
                         SFFQ)
                    values
                        (SEQ_QYTC.CURRVAL,
                         SEQ_YWLS.NEXTVAL,
                         SEQ_YWLS.NEXTVAL,
                         rc.QYBM,
                         ‘28‘,
                         rc.jhzt,
                         ‘0‘,
                         ‘预处理‘,
                         sysdate,
                         ‘jhzt‘,
                         rc.GHDM,
                         rc.GHMC,
                         rc.GHLX,
                         rc.ZHLX,
                         rc.QYGHRS,
                         rc.JHZT,
                         rc.JHSJ,
                         rc.SHSJ,
                         rc.JFLCBL,
                         rc.GHDM1,
                         rc.BL1,
                         rc.GHDM2,
                         rc.BL2,
                         rc.GHDM3,
                         rc.BL3,
                         rc.GHDM4,
                         rc.BL4,
                         rc.GHDM5,
                         rc.BL5,
                         rc.GHDM6,
                         rc.BL6,
                         rc.QYJC,
                         rc.DRRQ,
                         rc.QYMC,
                         rc.SJJYDZ,
                         rc.LXR,
                         rc.LXDH,
                         rc.KHH,
                         rc.KHZH,
                         rc.KHMC,
                         rc.JSJDM,
                         rc.TYSHXYDM,
                         rc.DJZCLXDM,
                         rc.ZZJGDM,
                         rc.JYDZ,
                         rc.JYDZYB,
                         rc.ZCDZ,
                         rc.ZCDZYB,
                         rc.JYDZLXDM,
                         rc.SWJGZZJGDM,
                         rc.SCJXDM,
                         rc.NSRZTMC,
                         rc.GJBZHYDM,
                         rc.KYDJRQ,
                         rc.SWDJLXMC,
                         rc.SJQYMC,
                         rc.SJJYDZYB,
                         rc.QYZT,
                         rc.QYFR,
                         rc.JHH,
                         rc.XEZFH,
                         rc.GSRS,
                         rc.SSGLYDM,
                         rc.ISTC,
                         rc.NSRSBH,
                         rc.XGRQ,
                         rc.SFFQ);
                end if;
            end if;
        
        end loop;
        ---2.2、如果scjxdm是空的,则根据经营地址来判断是否为京外经营
        for rc in scjxnull loop
            if ((instr(rc.jydz, ‘北京‘) = 0 or instr(rc.jydz, ‘东城区‘) = 0 or
               instr(rc.jydz, ‘西城区‘) = 0 or instr(rc.jydz, ‘朝阳区‘) = 0 or
               instr(rc.jydz, ‘丰台区‘) = 0 or instr(rc.jydz, ‘石景山区‘) = 0 or
               instr(rc.jydz, ‘海淀区‘) = 0 or instr(rc.jydz, ‘门头沟区‘) = 0 or
               instr(rc.jydz, ‘房山区‘) = 0 or instr(rc.jydz, ‘通州区‘) = 0 or
               instr(rc.jydz, ‘顺义区‘) = 0 or instr(rc.jydz, ‘昌平区‘) = 0 or
               instr(rc.jydz, ‘大兴区‘) = 0 or instr(rc.jydz, ‘怀柔区‘) = 0 or
               instr(rc.jydz, ‘平谷区‘) = 0 or instr(rc.jydz, ‘密云‘) = 0 or
               instr(rc.jydz, ‘延庆‘) = 0) and
               (instr(rc.jydz, ‘河北‘) > 0 or instr(rc.jydz, ‘山东‘) > 0 or
               instr(rc.jydz, ‘辽宁‘) > 0 or instr(rc.jydz, ‘黑龙江‘) > 0 or
               instr(rc.jydz, ‘江苏‘) > 0 or instr(rc.jydz, ‘湖北‘) > 0 or
               instr(rc.jydz, ‘湖南‘) > 0 or instr(rc.jydz, ‘河南‘) > 0 or
               instr(rc.jydz, ‘江西‘) > 0 or instr(rc.jydz, ‘浙江‘) > 0 or
               instr(rc.jydz, ‘广东‘) > 0 or instr(rc.jydz, ‘云南‘) > 0 or
               instr(rc.jydz, ‘福建‘) > 0 or instr(rc.jydz, ‘台湾‘) > 0 or
               instr(rc.jydz, ‘海南‘) > 0 or instr(rc.jydz, ‘山西‘) > 0 or
               instr(rc.jydz, ‘四川‘) > 0 or instr(rc.jydz, ‘陕西‘) > 0 or
               instr(rc.jydz, ‘贵州‘) > 0 or instr(rc.jydz, ‘安徽‘) > 0 or
               instr(rc.jydz, ‘重庆‘) > 0 or instr(rc.jydz, ‘上海‘) > 0 or
               instr(rc.jydz, ‘天津‘) > 0 or instr(rc.jydz, ‘广西‘) > 0 or
               instr(rc.jydz, ‘内蒙古‘) > 0 or instr(rc.jydz, ‘西藏‘) > 0 or
               instr(rc.jydz, ‘新疆‘) > 0 or instr(rc.jydz, ‘宁夏‘) > 0 or
               instr(rc.jydz, ‘澳门‘) > 0 or instr(rc.jydz, ‘香港‘) > 0 or
               instr(rc.jydz, ‘吉林‘) > 0 or instr(rc.jydz, ‘甘肃‘) > 0 or
               instr(rc.jydz, ‘青海‘) > 0 or instr(rc.jydz, ‘吉林‘) > 0 or
               instr(rc.jydz, ‘甘肃‘) > 0 or instr(rc.jydz, ‘青海‘) > 0)) then
                update GH_QYXX
                   SET ISTCCONDITION = ‘1‘
                 where qybm = rc.qybm;
                if (rc.jhzt in (‘0‘,
                                ‘1‘,
                                ‘2‘,
                                ‘3‘,
                                ‘4‘,
                                ‘5‘,
                                ‘6‘,
                                ‘7‘,
                                ‘8‘,
                                ‘9‘,
                                ‘10‘,
                                ‘11‘,
                                ‘12‘,
                                ‘13‘,
                                ‘14‘,
                                ‘15‘,
                                ‘16‘,
                                ‘17‘)) then
                    insert into GH_QYTC
                        (YWLSDM,
                         QYBM,
                         QYSQZT,
                         QYBQZT,
                         SFBL,
                         CZYYDM,
                         CZRYDM,
                         JHZT)
                    values
                        (SEQ_QYTC.NEXTVAL,
                         rc.qybm,
                         ‘1‘,
                         ‘1‘,
                         ‘0‘,
                         ‘京外经营‘,
                         ‘1‘,
                         rc.jhzt);
                    update gh_qyghgx set jhzt = ‘28‘ where qybm = rc.qybm;
                    -----增加变更历史表数据
                    insert into GH_QYBG_LS
                        (QYTCID,
                         ID,
                         YWLSDM,
                         QYBM,
                         BGXXZ,
                         BGXJZ,
                         SPZT,
                         CZRYDM,
                         CZSJ,
                         BGXDM,
                         GHDM,
                         GHMC,
                         GHLX,
                         ZHLX,
                         QYGHRS,
                         JHZT,
                         JHSJ,
                         SHSJ,
                         JFLCBL,
                         GHDM1,
                         BL1,
                         GHDM2,
                         BL2,
                         GHDM3,
                         BL3,
                         GHDM4,
                         BL4,
                         GHDM5,
                         BL5,
                         GHDM6,
                         BL6,
                         QYJC,
                         DRRQ,
                         QYMC,
                         SJJYDZ,
                         LXR,
                         LXDH,
                         KHH,
                         KHZH,
                         KHMC,
                         JSJDM,
                         TYSHXYDM,
                         DJZCLXDM,
                         ZZJGDM,
                         JYDZ,
                         JYDZYB,
                         ZCDZ,
                         ZCDZYB,
                         JYDZLXDM,
                         SWJGZZJGDM,
                         SCJXDM,
                         NSRZTMC,
                         GJBZHYDM,
                         KYDJRQ,
                         SWDJLXMC,
                         SJQYMC,
                         SJJYDZYB,
                         QYZT,
                         QYFR,
                         JHH,
                         XEZFH,
                         GSRS,
                         SSGLYDM,
                         ISTC,
                         NSRSBH,
                         XGRQ,
                         SFFQ)
                    values
                        (SEQ_QYTC.Currval,
                         SEQ_YWLS.NEXTVAL,
                         SEQ_YWLS.NEXTVAL,
                         rc.QYBM,
                         ‘28‘,
                         rc.jhzt,
                         ‘0‘,
                         ‘预处理‘,
                         sysdate,
                         ‘jhzt‘,
                         rc.GHDM,
                         rc.GHMC,
                         rc.GHLX,
                         rc.ZHLX,
                         rc.QYGHRS,
                         rc.JHZT,
                         rc.JHSJ,
                         rc.SHSJ,
                         rc.JFLCBL,
                         rc.GHDM1,
                         rc.BL1,
                         rc.GHDM2,
                         rc.BL2,
                         rc.GHDM3,
                         rc.BL3,
                         rc.GHDM4,
                         rc.BL4,
                         rc.GHDM5,
                         rc.BL5,
                         rc.GHDM6,
                         rc.BL6,
                         rc.QYJC,
                         rc.DRRQ,
                         rc.QYMC,
                         rc.SJJYDZ,
                         rc.LXR,
                         rc.LXDH,
                         rc.KHH,
                         rc.KHZH,
                         rc.KHMC,
                         rc.JSJDM,
                         rc.TYSHXYDM,
                         rc.DJZCLXDM,
                         rc.ZZJGDM,
                         rc.JYDZ,
                         rc.JYDZYB,
                         rc.ZCDZ,
                         rc.ZCDZYB,
                         rc.JYDZLXDM,
                         rc.SWJGZZJGDM,
                         rc.SCJXDM,
                         rc.NSRZTMC,
                         rc.GJBZHYDM,
                         rc.KYDJRQ,
                         rc.SWDJLXMC,
                         rc.SJQYMC,
                         rc.SJJYDZYB,
                         rc.QYZT,
                         rc.QYFR,
                         rc.JHH,
                         rc.XEZFH,
                         rc.GSRS,
                         rc.SSGLYDM,
                         rc.ISTC,
                         rc.NSRSBH,
                         rc.XGRQ,
                         rc.SFFQ);
                else
                    insert into GH_QYTC_LS
                        (YWLSDM,
                         QYBM,
                         QYSQZT,
                         QYBQZT,
                         SFBL,
                         CZYYDM,
                         CZRYDM,
                         JHZT)
                    values
                        (SEQ_QYTC.Nextval,
                         rc.qybm,
                         ‘1‘,
                         ‘1‘,
                         ‘1‘,
                         ‘京外经营‘,
                         ‘1‘,
                         rc.jhzt);
                    if (rc.jhzt != ‘28‘) then
                        ---修改建会状态
                        update gh_qyghgx
                           set jhzt = ‘28‘
                         where qybm = rc.qybm;
                        -----(未建会的)增加变更历史表数据
                        insert into GH_QYBG_LS
                            (QYTCID,
                             ID,
                             YWLSDM,
                             QYBM,
                             BGXXZ,
                             BGXJZ,
                             SPZT,
                             CZRYDM,
                             CZSJ,
                             BGXDM,
                             GHDM,
                             GHMC,
                             GHLX,
                             ZHLX,
                             QYGHRS,
                             JHZT,
                             JHSJ,
                             SHSJ,
                             JFLCBL,
                             GHDM1,
                             BL1,
                             GHDM2,
                             BL2,
                             GHDM3,
                             BL3,
                             GHDM4,
                             BL4,
                             GHDM5,
                             BL5,
                             GHDM6,
                             BL6,
                             QYJC,
                             DRRQ,
                             QYMC,
                             SJJYDZ,
                             LXR,
                             LXDH,
                             KHH,
                             KHZH,
                             KHMC,
                             JSJDM,
                             TYSHXYDM,
                             DJZCLXDM,
                             ZZJGDM,
                             JYDZ,
                             JYDZYB,
                             ZCDZ,
                             ZCDZYB,
                             JYDZLXDM,
                             SWJGZZJGDM,
                             SCJXDM,
                             NSRZTMC,
                             GJBZHYDM,
                             KYDJRQ,
                             SWDJLXMC,
                             SJQYMC,
                             SJJYDZYB,
                             QYZT,
                             QYFR,
                             JHH,
                             XEZFH,
                             GSRS,
                             SSGLYDM,
                             ISTC,
                             NSRSBH,
                             XGRQ,
                             SFFQ)
                        values
                            (SEQ_QYTC.CURRVAL,
                             SEQ_YWLS.NEXTVAL,
                             SEQ_YWLS.NEXTVAL,
                             rc.QYBM,
                             ‘28‘,
                             rc.jhzt,
                             ‘0‘,
                             ‘预处理‘,
                             sysdate,
                             ‘jhzt‘,
                             rc.GHDM,
                             rc.GHMC,
                             rc.GHLX,
                             rc.ZHLX,
                             rc.QYGHRS,
                             rc.JHZT,
                             rc.JHSJ,
                             rc.SHSJ,
                             rc.JFLCBL,
                             rc.GHDM1,
                             rc.BL1,
                             rc.GHDM2,
                             rc.BL2,
                             rc.GHDM3,
                             rc.BL3,
                             rc.GHDM4,
                             rc.BL4,
                             rc.GHDM5,
                             rc.BL5,
                             rc.GHDM6,
                             rc.BL6,
                             rc.QYJC,
                             rc.DRRQ,
                             rc.QYMC,
                             rc.SJJYDZ,
                             rc.LXR,
                             rc.LXDH,
                             rc.KHH,
                             rc.KHZH,
                             rc.KHMC,
                             rc.JSJDM,
                             rc.TYSHXYDM,
                             rc.DJZCLXDM,
                             rc.ZZJGDM,
                             rc.JYDZ,
                             rc.JYDZYB,
                             rc.ZCDZ,
                             rc.ZCDZYB,
                             rc.JYDZLXDM,
                             rc.SWJGZZJGDM,
                             rc.SCJXDM,
                             rc.NSRZTMC,
                             rc.GJBZHYDM,
                             rc.KYDJRQ,
                             rc.SWDJLXMC,
                             rc.SJQYMC,
                             rc.SJJYDZYB,
                             rc.QYZT,
                             rc.QYFR,
                             rc.JHH,
                             rc.XEZFH,
                             rc.GSRS,
                             rc.SSGLYDM,
                             rc.ISTC,
                             rc.NSRSBH,
                             rc.XGRQ,
                             rc.SFFQ);
                    end if;
                end if;
            end if;
        end loop;
        insert into YUCHULI_MARK values (SYS_GUID(), ‘经外经营‘, sysdate);
        commit;
        --3、空壳单位
        ---4联合工会-不应代收-空壳单位   13独立工会-不应代收-空壳单位  21未建会-不应代收-空壳单位
        ---3.1已建会空壳:已建会单位中,最近一个季度个税月申报人数小于等于2人或个税月申报金额为零元的单位。
        ---单位的建会状态保持不变,代收类型改为不应代收,代收因素改为空壳单位。
        for rc in jh loop
            update GH_QYXX SET ISTCCONDITION = ‘1‘ where qybm = rc.qybm;
            if (rc.jhzt in (‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘)) then
                ---联合工会
                insert into GH_QYTC
                    (YWLSDM,
                     QYBM,
                     QYSQZT,
                     QYBQZT,
                     SFBL,
                     CZYYDM,
                     CZRYDM,
                     JHZT)
                values
                    (SEQ_QYTC.NEXTVAL,
                     rc.qybm,
                     ‘1‘,
                     ‘1‘,
                     ‘0‘,
                     ‘空壳单位‘,
                     ‘1‘,
                     rc.jhzt);
                if (rc.jhzt != ‘4‘) then
                    update gh_qyghgx set jhzt = ‘4‘ where qybm = rc.qybm;
                    -----增加变更历史表数据
                    insert into GH_QYBG_LS
                        (QYTCID,
                         ID,
                         YWLSDM,
                         QYBM,
                         BGXXZ,
                         BGXJZ,
                         SPZT,
                         CZRYDM,
                         CZSJ,
                         BGXDM,
                         GHDM,
                         GHMC,
                         GHLX,
                         ZHLX,
                         QYGHRS,
                         JHZT,
                         JHSJ,
                         SHSJ,
                         JFLCBL,
                         GHDM1,
                         BL1,
                         GHDM2,
                         BL2,
                         GHDM3,
                         BL3,
                         GHDM4,
                         BL4,
                         GHDM5,
                         BL5,
                         GHDM6,
                         BL6,
                         QYJC,
                         DRRQ,
                         QYMC,
                         SJJYDZ,
                         LXR,
                         LXDH,
                         KHH,
                         KHZH,
                         KHMC,
                         JSJDM,
                         TYSHXYDM,
                         DJZCLXDM,
                         ZZJGDM,
                         JYDZ,
                         JYDZYB,
                         ZCDZ,
                         ZCDZYB,
                         JYDZLXDM,
                         SWJGZZJGDM,
                         SCJXDM,
                         NSRZTMC,
                         GJBZHYDM,
                         KYDJRQ,
                         SWDJLXMC,
                         SJQYMC,
                         SJJYDZYB,
                         QYZT,
                         QYFR,
                         JHH,
                         XEZFH,
                         GSRS,
                         SSGLYDM,
                         ISTC,
                         NSRSBH,
                         XGRQ,
                         SFFQ)
                    values
                        (SEQ_QYTC.Currval,
                         SEQ_YWLS.NEXTVAL,
                         SEQ_YWLS.NEXTVAL,
                         rc.QYBM,
                         ‘4‘,
                         rc.jhzt,
                         ‘0‘,
                         ‘预处理‘,
                         sysdate,
                         ‘jhzt‘,
                         rc.GHDM,
                         rc.GHMC,
                         rc.GHLX,
                         rc.ZHLX,
                         rc.QYGHRS,
                         rc.JHZT,
                         rc.JHSJ,
                         rc.SHSJ,
                         rc.JFLCBL,
                         rc.GHDM1,
                         rc.BL1,
                         rc.GHDM2,
                         rc.BL2,
                         rc.GHDM3,
                         rc.BL3,
                         rc.GHDM4,
                         rc.BL4,
                         rc.GHDM5,
                         rc.BL5,
                         rc.GHDM6,
                         rc.BL6,
                         rc.QYJC,
                         rc.DRRQ,
                         rc.QYMC,
                         rc.SJJYDZ,
                         rc.LXR,
                         rc.LXDH,
                         rc.KHH,
                         rc.KHZH,
                         rc.KHMC,
                         rc.JSJDM,
                         rc.TYSHXYDM,
                         rc.DJZCLXDM,
                         rc.ZZJGDM,
                         rc.JYDZ,
                         rc.JYDZYB,
                         rc.ZCDZ,
                         rc.ZCDZYB,
                         rc.JYDZLXDM,
                         rc.SWJGZZJGDM,
                         rc.SCJXDM,
                         rc.NSRZTMC,
                         rc.GJBZHYDM,
                         rc.KYDJRQ,
                         rc.SWDJLXMC,
                         rc.SJQYMC,
                         rc.SJJYDZYB,
                         rc.QYZT,
                         rc.QYFR,
                         rc.JHH,
                         rc.XEZFH,
                         rc.GSRS,
                         rc.SSGLYDM,
                         rc.ISTC,
                         rc.NSRSBH,
                         rc.XGRQ,
                         rc.SFFQ);
                end if;
            elsif (rc.jhzt in
                  (‘9‘, ‘10‘, ‘11‘, ‘12‘, ‘13‘, ‘14‘, ‘15‘, ‘16‘, ‘17‘)) then
                --独立工会
                insert into GH_QYTC
                    (YWLSDM,
                     QYBM,
                     QYSQZT,
                     QYBQZT,
                     SFBL,
                     CZYYDM,
                     CZRYDM,
                     JHZT)
                values
                    (SEQ_QYTC.NEXTVAL,
                     rc.qybm,
                     ‘1‘,
                     ‘1‘,
                     ‘0‘,
                     ‘空壳单位‘,
                     ‘1‘,
                     rc.jhzt);
                if (rc.jhzt != ‘13‘) then
                    update gh_qyghgx set jhzt = ‘13‘ where qybm = rc.qybm;
                    -----增加变更历史表数据
                    insert into GH_QYBG_LS
                        (QYTCID,
                         ID,
                         YWLSDM,
                         QYBM,
                         BGXXZ,
                         BGXJZ,
                         SPZT,
                         CZRYDM,
                         CZSJ,
                         BGXDM,
                         GHDM,
                         GHMC,
                         GHLX,
                         ZHLX,
                         QYGHRS,
                         JHZT,
                         JHSJ,
                         SHSJ,
                         JFLCBL,
                         GHDM1,
                         BL1,
                         GHDM2,
                         BL2,
                         GHDM3,
                         BL3,
                         GHDM4,
                         BL4,
                         GHDM5,
                         BL5,
                         GHDM6,
                         BL6,
                         QYJC,
                         DRRQ,
                         QYMC,
                         SJJYDZ,
                         LXR,
                         LXDH,
                         KHH,
                         KHZH,
                         KHMC,
                         JSJDM,
                         TYSHXYDM,
                         DJZCLXDM,
                         ZZJGDM,
                         JYDZ,
                         JYDZYB,
                         ZCDZ,
                         ZCDZYB,
                         JYDZLXDM,
                         SWJGZZJGDM,
                         SCJXDM,
                         NSRZTMC,
                         GJBZHYDM,
                         KYDJRQ,
                         SWDJLXMC,
                         SJQYMC,
                         SJJYDZYB,
                         QYZT,
                         QYFR,
                         JHH,
                         XEZFH,
                         GSRS,
                         SSGLYDM,
                         ISTC,
                         NSRSBH,
                         XGRQ,
                         SFFQ)
                    values
                        (SEQ_QYTC.Currval,
                         SEQ_YWLS.NEXTVAL,
                         SEQ_YWLS.NEXTVAL,
                         rc.QYBM,
                         ‘13‘,
                         rc.jhzt,
                         ‘0‘,
                         ‘预处理‘,
                         sysdate,
                         ‘jhzt‘,
                         rc.GHDM,
                         rc.GHMC,
                         rc.GHLX,
                         rc.ZHLX,
                         rc.QYGHRS,
                         rc.JHZT,
                         rc.JHSJ,
                         rc.SHSJ,
                         rc.JFLCBL,
                         rc.GHDM1,
                         rc.BL1,
                         rc.GHDM2,
                         rc.BL2,
                         rc.GHDM3,
                         rc.BL3,
                         rc.GHDM4,
                         rc.BL4,
                         rc.GHDM5,
                         rc.BL5,
                         rc.GHDM6,
                         rc.BL6,
                         rc.QYJC,
                         rc.DRRQ,
                         rc.QYMC,
                         rc.SJJYDZ,
                         rc.LXR,
                         rc.LXDH,
                         rc.KHH,
                         rc.KHZH,
                         rc.KHMC,
                         rc.JSJDM,
                         rc.TYSHXYDM,
                         rc.DJZCLXDM,
                         rc.ZZJGDM,
                         rc.JYDZ,
                         rc.JYDZYB,
                         rc.ZCDZ,
                         rc.ZCDZYB,
                         rc.JYDZLXDM,
                         rc.SWJGZZJGDM,
                         rc.SCJXDM,
                         rc.NSRZTMC,
                         rc.GJBZHYDM,
                         rc.KYDJRQ,
                         rc.SWDJLXMC,
                         rc.SJQYMC,
                         rc.SJJYDZYB,
                         rc.QYZT,
                         rc.QYFR,
                         rc.JHH,
                         rc.XEZFH,
                         rc.GSRS,
                         rc.SSGLYDM,
                         rc.ISTC,
                         rc.NSRSBH,
                         rc.XGRQ,
                         rc.SFFQ);
                end if;
            end if;
        end loop;
        insert into YUCHULI_MARK
        values
            (SYS_GUID(), ‘已建会空壳‘, sysdate);
        commit;
        ---3.2未建会空壳:最近一个月个税月申报人数小于等于2人或个税月申报金额为零元的单位。
        ----单位的建会状态保持不变,代收类型改为不应代收,代收因素改为空壳单位。
        for rc in nojh loop
            update GH_QYXX SET ISTCCONDITION = ‘1‘ where qybm = rc.qybm; --修改标记状态
            ---添加到剔除表中
            insert into GH_QYTC_LS
                (YWLSDM, QYBM, QYSQZT, QYBQZT, SFBL, CZYYDM, CZRYDM, JHZT)
            values
                (SEQ_QYTC.Nextval,
                 rc.qybm,
                 ‘1‘,
                 ‘1‘,
                 ‘1‘,
                 ‘空壳单位‘,
                 ‘1‘,
                 rc.jhzt);
            ---未建会空壳:最近一个月个税月申报人数小于等于2人或个税月申报金额为零元的单位。
            ---单位的建会状态保持不变,代收类型改为不应代收,代收因素改为空壳单位。
            if (rc.jhzt != ‘21‘) then
                update gh_qyghgx set jhzt = ‘21‘ where qybm = rc.qybm;
                -----增加变更历史表数据
                insert into GH_QYBG_LS
                    (QYTCID,
                     ID,
                     YWLSDM,
                     QYBM,
                     BGXXZ,
                     BGXJZ,
                     SPZT,
                     CZRYDM,
                     CZSJ,
                     BGXDM,
                     GHDM,
                     GHMC,
                     GHLX,
                     ZHLX,
                     QYGHRS,
                     JHZT,
                     JHSJ,
                     SHSJ,
                     JFLCBL,
                     GHDM1,
                     BL1,
                     GHDM2,
                     BL2,
                     GHDM3,
                     BL3,
                     GHDM4,
                     BL4,
                     GHDM5,
                     BL5,
                     GHDM6,
                     BL6,
                     QYJC,
                     DRRQ,
                     QYMC,
                     SJJYDZ,
                     LXR,
                     LXDH,
                     KHH,
                     KHZH,
                     KHMC,
                     JSJDM,
                     TYSHXYDM,
                     DJZCLXDM,
                     ZZJGDM,
                     JYDZ,
                     JYDZYB,
                     ZCDZ,
                     ZCDZYB,
                     JYDZLXDM,
                     SWJGZZJGDM,
                     SCJXDM,
                     NSRZTMC,
                     GJBZHYDM,
                     KYDJRQ,
                     SWDJLXMC,
                     SJQYMC,
                     SJJYDZYB,
                     QYZT,
                     QYFR,
                     JHH,
                     XEZFH,
                     GSRS,
                     SSGLYDM,
                     ISTC,
                     NSRSBH,
                     XGRQ,
                     SFFQ)
                values
                    (SEQ_QYTC.Currval,
                     SEQ_YWLS.NEXTVAL,
                     SEQ_YWLS.NEXTVAL,
                     rc.QYBM,
                     ‘21‘,
                     rc.jhzt,
                     ‘0‘,
                     ‘预处理‘,
                     sysdate,
                     ‘jhzt‘,
                     rc.GHDM,
                     rc.GHMC,
                     rc.GHLX,
                     rc.ZHLX,
                     rc.QYGHRS,
                     rc.JHZT,
                     rc.JHSJ,
                     rc.SHSJ,
                     rc.JFLCBL,
                     rc.GHDM1,
                     rc.BL1,
                     rc.GHDM2,
                     rc.BL2,
                     rc.GHDM3,
                     rc.BL3,
                     rc.GHDM4,
                     rc.BL4,
                     rc.GHDM5,
                     rc.BL5,
                     rc.GHDM6,
                     rc.BL6,
                     rc.QYJC,
                     rc.DRRQ,
                     rc.QYMC,
                     rc.SJJYDZ,
                     rc.LXR,
                     rc.LXDH,
                     rc.KHH,
                     rc.KHZH,
                     rc.KHMC,
                     rc.JSJDM,
                     rc.TYSHXYDM,
                     rc.DJZCLXDM,
                     rc.ZZJGDM,
                     rc.JYDZ,
                     rc.JYDZYB,
                     rc.ZCDZ,
                     rc.ZCDZYB,
                     rc.JYDZLXDM,
                     rc.SWJGZZJGDM,
                     rc.SCJXDM,
                     rc.NSRZTMC,
                     rc.GJBZHYDM,
                     rc.KYDJRQ,
                     rc.SWDJLXMC,
                     rc.SJQYMC,
                     rc.SJJYDZYB,
                     rc.QYZT,
                     rc.QYFR,
                     rc.JHH,
                     rc.XEZFH,
                     rc.GSRS,
                     rc.SSGLYDM,
                     rc.ISTC,
                     rc.NSRSBH,
                     rc.XGRQ,
                     rc.SFFQ);
            end if;
        end loop;
        insert into YUCHULI_MARK values (SYS_GUID(), ‘delete‘, sysdate);
        commit;
    end;

end yuchuli_delete;

sql_delete_2017/11/1

标签:.sh   怀柔区   证件   delete   朝阳区   ext   福建   cursor   修改   

原文地址:http://www.cnblogs.com/523823-wu/p/7768217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!