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

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

时间:2014-09-02 12:29:14      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   for   数据   2014   log   on   line   

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;

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

标签:blog   io   ar   for   数据   2014   log   on   line   

原文地址:http://blog.csdn.net/without0815/article/details/39003173

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