Write a simple stored procedure instance note

Source: Internet
Author: User

1, run on phpMyAdmin, for inserting data, associating product with freight chart

1 /*To define a stored procedure decomposition character*/2Delimiter//3 DROP PROCEDURE IF EXISTSDoshipping//4 CREATE PROCEDUREdoshipping ()5 BEGIN6     /*declaring Variables*/7     DECLARENo_more_recordINT DEFAULT 0;8     DECLAREIINT;9     DECLAREEntityIdBIGINT(Ten);Ten     /*creating a cursor variable*/ One     DECLARECur_recordCURSOR  for SELECTentity_id fromCatalog_product_entityORDER  byentity_idDESC; A     DECLARE CONTINUEHANDLER for  notFOUNDSETNo_more_record=1; -  -     OPENCur_record; the     /*Fetching cursor Variables*/ -     FETCHCur_record intoEntityId; -     /*loop to get each product ID*/ -      whileNo_more_record!=1 Do +         SETI=0; -         /*cyclic correlation for each product associated freight*/ +          whileI<4 Do A              CaseI at                  when 0  Then -                 INSERT  intodirectory_country_shipping (Group_product_id,ship_method,ship_cost,ship_eachadd,ship_listcountry, -Delivery_time,show_order,created_time,update_time)VALUES(EntityId,' Free','0.00','0.00','All Country','15-30','0', now (), now ());  -                  when 1  Then -                 INSERT  intoyo_directory_country_shipping (Group_product_id,ship_method,ship_cost,ship_eachadd,ship_listcountry, -Delivery_time,show_order,created_time,update_time)VALUES(EntityId,' Standard','10.00','2.00','All Country','10-15','1', now (), now ());  in                  when 2  Then -                 INSERT  intoyo_directory_country_shipping (Group_product_id,ship_method,ship_cost,ship_eachadd,ship_listcountry, toDelivery_time,show_order,created_time,update_time)VALUES(EntityId,'Economical','9.00','3.00','All Country','5-10','2', now (), now ());  +                 ELSE -                 INSERT  intoyo_directory_country_shipping (Group_product_id,ship_method,ship_cost,ship_eachadd,ship_listcountry, theDelivery_time,show_order,created_time,update_time)VALUES(EntityId,'Speedy','8.00','2.00','All Country','3-5','3', now (), now ());  *             END  Case;  $             SETI=I+1;Panax Notoginseng         END  while; -         FETCHCur_record intoEntityId; the     END  while; +     /*Close cursor Variable*/ A     CLOSECur_record; the END;// +delimiter;

Write a simple stored procedure instance note

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.