Mysql stored Procedure implementation split sample _mysql

Source: Internet
Author: User

Copy Code code as follows:

Call Procedure_split (' share, code, fragment ', ', ', ');
SELECT * from SplitTable;

Copy Code code 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.