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数据