oracle存储过程0009

create or replace procedure XS_TEST_UPDATE_BAC is
  str_BeginStr varchar2(20);
  str_EndStr   varchar2(20);
  cursor curTestUpdateBac is
    select id,
           substr(bachelor_edu,
                  instr(bachelor_edu, '从') + 1,
                  instr(bachelor_edu, '年到') - 2) as startYear,
           substr(substr(bachelor_edu, instr(bachelor_edu, '年到') + 2),
                  1,
                  instr(substr(bachelor_edu, instr(bachelor_edu, '年到') + 2),
                        '年') - 1) as endYear,
           substr(substr(bachelor_edu, instr(bachelor_edu, '年到') + 2),
                  instr(substr(bachelor_edu, instr(bachelor_edu, '年到') + 2),
                        '年') + 1) as yuanxi,
           bachelor_edu
      from dcp_apps.test_alumni_user
     where bachelor_edu <> '从年到年'
       and bachelor_edu <> '无'
       and instr(bachelor_edu, '年到') > 0;

  --校友用户类型
  rec_curTestUpdateBac curTestUpdateBac%rowtype;

begin
  --判断游标是否被打开,如果已经打开,首先关闭
  if curTestUpdateBac%isopen then
    --关闭游标
    close curTestUpdateBac;
  end if;
  --打开游标
  open curTestUpdateBac;
  --进行循环
  loop
    --打开游标里的一条记录,赋到游标变量里
    fetch curTestUpdateBac
      into rec_curTestUpdateBac;
    --判断游标里是否还有记录,如果没有记录,关闭游标,退出循环
    if curTestUpdateBac%notfound then
      close curTestUpdateBac;
      exit;
    else
      if (rec_curTestUpdateBac.Startyear != 'undefined' or
         rec_curTestUpdateBac.Endyear != 'undefined' or
         rec_curTestUpdateBac.Yuanxi != 'undefined') then
         --修改本科字段全角字符为半角字符
         update dcp_apps.TEST_alumni_user a1 set a1.bachelor_edu=to_single_byte(a1.bachelor_edu)  where a1.id=rec_curTestUpdateBac.Id;
         str_BeginStr := substr(rec_curTestUpdateBac.Startyear, 1, 1);
         str_EndStr:=substr(rec_curTestUpdateBac.Endyear,1,1);
       if (str_BeginStr!='0' and str_BeginStr!='1' and str_BeginStr!='2') then
            update test_alumni_user u
            set u.bachelor_edu_begin_day = '19'||rec_curTestUpdateBac.Startyear,
                u.bachelor_edu_end_day   = rec_curTestUpdateBac.Endyear,              
                u.bachelor_departments   = rec_curTestUpdateBac.Yuanxi
                where u.id = rec_curTestUpdateBac.Id;          
         else
             if(str_BeginStr='0')then
              update dcp_apps.test_alumni_user u
                 set u.bachelor_edu_begin_day = '20'||rec_curTestUpdateBac.Startyear,
                 u.bachelor_edu_end_day   = rec_curTestUpdateBac.Endyear,
                 u.bachelor_departments   = rec_curTestUpdateBac.Yuanxi
                 where u.id = rec_curTestUpdateBac.Id;           
             else
             update dcp_apps.test_alumni_user u
                 set u.bachelor_edu_begin_day = rec_curTestUpdateBac.Startyear,
                 u.bachelor_edu_end_day   = rec_curTestUpdateBac.Endyear,
                 u.bachelor_departments   = rec_curTestUpdateBac.Yuanxi
                 where u.id = rec_curTestUpdateBac.Id;    
             end if;   
         end if;
        
         if(str_EndStr!='0' and str_EndStr!='1' and str_EndStr!='2')then
           update dcp_apps.test_alumni_user u
           set
               u.bachelor_edu_end_day   = '19'||rec_curTestUpdateBac.Endyear,
               u.bachelor_departments   = rec_curTestUpdateBac.Yuanxi
             where u.id = rec_curTestUpdateBac.Id;
         else
             if(str_EndStr='0')then
               update dcp_apps.test_alumni_user u
                 set
                     u.bachelor_edu_end_day   = '20'||rec_curTestUpdateBac.Endyear,
                     u.bachelor_departments   = rec_curTestUpdateBac.Yuanxi
                     where u.id = rec_curTestUpdateBac.Id;
             end if;    
         end if;      
      end if;
    end if;
    commit;
  end loop;
exception
  when others then
    rollback;
end XS_TEST_UPDATE_BAC;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值