MySQL Stored Procedure Implementation split

Source: Internet
Author: User
MySQL Stored procedure Implementation; CREATEPROCEDURE 'Procedure _ split '(inputstringvarchar (1000), delimchar (1) begindeclarestrlenintDEFAULTlength (inputstring); declarelast_indexintDEFAULT0; decia

MySQL Stored PROCEDURE Implementation split MySQL drop PROCEDURE if exists procedure_split; CREATE procedure 'Procedure _ split '(inputstring varchar (1000), delim char (1 )) begin declare strlen int DEFAULT length (inputstring); declare last_index int DEFAULT 0; decia

MySQL Stored Procedure Implementation split MySQL
drop PROCEDURE if exists procedure_split;CREATE PROCEDURE `procedure_split`(    inputstring varchar(1000),    delim char(1))begin    declare strlen int DEFAULT length(inputstring);    declare last_index int DEFAULT 0;    declare cur_index int DEFAULT 1;    declare cur_char VARCHAR(200);    declare len int;    drop temporary table if exists splittable;    create TEMPORARY table splittable(        value VARCHAR(20)    ) ;    WHILE(cur_index<=strlen) DO        begin        if substring(inputstring from cur_index for 1)=delim or cur_index=strlen then            set len=cur_index-last_index-1;            if cur_index=strlen then               set len=len+1;            end if;            insert into splittable(`value`)values(substring(inputstring from (last_index+1) for len));            set last_index=cur_index;        end if;        set cur_index=cur_index+1;    END;    end while;end ;
Call PROCEDURE_split ('China, open source, ',', '); select * from splittable;

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.