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;