Mysql Stored Procedure Implementation split example

Source: Internet
Author: User

Copy codeThe Code is as follows:
Call PROCEDURE_split ('share, code, fragment ',',');
Select * from splittable;

Copy codeThe Code is as follows:
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;

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.