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;