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