oracle存储过程+游标处理select数据

create or replace
PROCEDURE UPDATE_RECORDCODE is
  cursor location_data is select * from location where remark in('952701','9527008','952705');--申明游标
  serviceCode NUMBER:=1;
BEGIN
    for l in location_data loop  --遍历游标
      BEGIN
        --业务处理
         UPDATE SERIAL_CODE SET CUR_NUMBER = CUR_NUMBER +1 where AREA_CODE=l.area_code and LOC_TYPE=l.type;
         select  CUR_NUMBER into serviceCode from SERIAL_CODE where AREA_CODE=l.area_code and LOC_TYPE=l.type;
         
         update location lu set putrecord_code=(l.area_code||'0'||l.type||lpad(serviceCode,6,0)) where lu.id=l.id; 
         --dbms_output.put_line(ServiceCode);
         EXCEPTION--异常处理
        WHEN NO_DATA_FOUND THEN 
           INSERT INTO SERIAL_CODE (AREA_CODE, LOC_TYPE,CUR_NUMBER) VALUES (l.area_code,l.type,1);
       end;
    end loop; 
    commit;
END UPDATE_RECORDCODE;

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。