MySQL stored procedure: Batch update data

Source: Internet
Author: User

Information on the regional level is stored in the Jsjh_district table.

To update the District_level region information for the Jsjh_goods_district table

DELIMITER $$DROP PROCEDURE IF EXISTSUpdate_district_level $$CREATE PROCEDUREUpdate_district_level ()BEGINDECLARErow_idINT; #定义变量IDDECLARErow_district_idINT; #定义变量地区IDDECLARERow_levelINT; #定义变量地区等级DECLAREDoneINT;--Defining CursorsDECLARERs_cursorCURSOR  forSELECTMain.id,main.district_id,d. ' Level` fromJsjh_goods_district Main Left JOINJsjh_district D onD.id=main.district_id;DECLARE CONTINUEHANDLER for  notFOUNDSETDone=1;OPENrs_cursor; Cursor_loop:loopFETCHRs_cursor intoRow_id,row_district_id,row_level;--Fetch DataIFDone=1  Thenleave Cursor_loop;END IF;--Update tableUPDATEJsjh_goods_districtSETDistrict_level=Row_levelWHEREId=row_id;ENDLOOP Cursor_loop;CLOSERs_cursor;END$ $DELIMITER;

Executing stored procedures

Call Update_district_level ();

/* Affected rows:0 has found records: 0 Warning: 0 Duration 1 query:1.014 sec. */

More than 1 seconds of execution time

MySQL stored procedure: Batch update data

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.