Re: Split String
here is a sample
DELIMITER $$;
DROP PROCEDURE IF EXISTS `db`.`split`$$
CREATE PROCEDURE `split`(input text, delim VARCHAR(10))
begin
declare foundPos tinyint unsigned;
declare tmpTxt text;
declare delimLen tinyint unsigned;
declare element text;
drop temporary table if exists tmpValues;
create temporary table tmpValues
(
`values` text not null default ''
) engine = memory;
set delimLen = length(delim);
set tmpTxt = input;
set foundPos = instr(tmpTxt,delim);
while foundPos <> 0 do
set element = substring(tmpTxt, 1, foundPos-1);
set tmpTxt = replace(tmpTxt, concat(element,delim), '');
insert into tmpValues (`values`) values ( element);
set foundPos = instr(tmpTxt,delim);
end while;
if tmpTxt <> '' then
insert into tmpValues (`values`) values (tmpTxt);
end if;
select * from tmpValues;
END$$
DELIMITER ;$$
Edited 1 time(s). Last edit at 04/12/2007 04:30AM by George Enciu.
Subject
Written By
Posted
Re: Split String
April 12, 2007 04:29AM
December 17, 2007 09:46AM
February 20, 2008 12:29PM
September 08, 2008 04:27AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.