1 BEGIN2 #Routine body goes here ...3 /*4 Update Szzx_goods_common set gc_id=i where Gc_name= (SELECT gc_name from Szzx_goods_class where gc_id=i);5 */6 DECLAREI,goodsidint( One);7 DeclareGoodsname,imgVarCHAR( $);8 SetI=104;9 whileI<1815 DoTen SELECTimage_url,goods_id intoImg,goodsid fromGoods_imagewhereimage_id=i; One#SELECTgoods_id intoGoodsid fromEcm_goods_imagewhereimgage_id=i; A SELECTGoods_name intoGoodsname fromEcm_goodswheregoods_id=Goodsid; - Selectgoods_id intoGoodsid fromSzzx_goodswhereGoods_name=Goodsname; - INSERT intoSzzx_goods_images (Goods_commonid,store_id,goods_image,goods_image_sort)VALUES(Goodsid,1Img1); the SetI=I+1; - - End while; - RETURN 0; + ENd
1. When using variables, define the variables and then assign them to the bottom. Multiple variable types are consistent and can be formatted with declare variable name 1, variable name 2.
2, in a function or procedure to assign a value to a variable with a SELECT statement, the format should be: Select field 1, field 2 into variable 1, variable 2 from table name format
MySQL custom functions and procedural considerations