MySQL stored procedure: Batch update data 2 (product brand)

Source: Internet
Author: User

EXECUTE statement

DELIMITER $$DROP PROCEDURE IF EXISTSjsjh_goods_property_value_update$$CREATE PROCEDUREjsjh_goods_property_value_update ()BEGINDECLARERow_base_brandvarchar( -); #定义变量品牌DECLARERow_titlevarchar( -); #定义tleteDECLARERow_valuevarchar( -); #定义valueDECLAREDoneINT;--Defining CursorsDECLARERs_cursorCURSOR  forSELECTA.base_brand,b.title fromJsjh_goods_item A Left JOINJsjh_goods_property_value b on(B.title=A.base_brand andb.property_id=1  andb.deleted=0)WHEREA.base_brand<>"'UNIONSELECTA.base_brand,b.title fromJsjh_goods_item A Right JOINJsjh_goods_property_value b on(B.title=A.base_brand andA.base_brand<>"')WHEREb.property_id=1  andb.deleted=0;DECLARE CONTINUEHANDLER for  notFOUNDSETDone=1;OPENrs_cursor; Cursor_loop:loopFETCHRs_cursor intoRow_base_brand,row_title;IFDone=1  Thenleave Cursor_loop;END IF;--Update tableIFRow_title is NULL  andRow_base_brand is  not NULL  ThenINSERT  intoJsjh_goods_property_value (property_id,value,title,showed)Values(1, Row_base_brand,row_base_brand,1);END IF;IFRow_base_brand is NULL  andRow_title is  not NULL  ThenUPDATEJsjh_goods_property_valueSETDeleted=Unix_timestamp ()WHERETitle=Row_title;END IF;ENDLOOP Cursor_loop;CLOSERs_cursor;END$ $DELIMITER;

MySQL stored procedure: Batch update data 2 (product brand)

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.