MySQL String processing example

Source: Internet
Author: User

In the project, to determine a certain number of fields in the table, if a value is replaced, using a few typical string operations, the record Note implementation scheme is as follows:

Note: If the substitution string is unique, you can use replace, where the concat stitching is used.

DELIMITER//DROP PROCEDURE IF EXISTSp_modify_year;CREATE PROCEDUREp_modify_year ()BEGIN    DECLARETmpidint(8); DECLARETmppciddvarchar( -); DECLARETmpprocodevarchar( -); DECLAREDoneINT DEFAULTFALSE; DECLARECurCURSOR  for SELECTProduct.id fromProductWHEREProstatus=0; DECLARE CONTINUEHANDLER for  notFOUNDSETDone=TRUE; OPENcur; Myloop:loopFETCHCur intoTmpid; IFDone ThenLEAVE Myloop; END IF; SELECT SUBSTRING(Product.pcidd,2,2), Product.procode intoTmppcidd, Tmpprocode fromProductWHEREId=Tmpid;
     The 2nd and 3 bits in//pcidd and Procode are replaced by AU, where procode may be empty. IFTmppcidd= ' -' Then UPDATEupe_productSetPcidd=CONCAT (SUBSTRING(Pcidd,1,1),'AU',SUBSTRING(Pcidd,4, LENGTH (Pcidd)+1)) WHEREId=Tmpid; IF!ISNULL(Tmpprocode) Then UPDATEProductSetProcode=CONCAT (SUBSTRING(Procode,1,1),'AU',SUBSTRING(Procode,4, LENGTH (Procode)+1))WHEREId=Tmpid; END IF; END IF; SETTmpprocode= NULL; SETTmppcidd= NULL; SETDone=FALSE; ENDLOOP; CLOSEcur; END//

MySQL String processing example

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.