Oracle Stored Procedure + cursor processing select data

Source: Internet
Author: User

Oracle Stored Procedure + cursor processing select data

Create or replacePROCEDURE UPDATE_RECORDCODE is cursor location_data is select * from location where remark in ('20160301', '20160301', '20160301'); -- declare the cursor serviceCode NUMBER: = 1; BEGIN for l in location_data loop -- traverse cursor BEGIN -- business processing 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 -- EXCEPTION Handling WHEN NO_DATA_FOUND then insert into SERIAL_CODE (AREA_CODE, LOC_TYPE, CUR_NUMBER) VALUES (l. area_code, l. type, 1); end loop; commit; END UPDATE_RECORDCODE;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.