MySQL Forums
Forum List  »  Microsoft SQL Server

Re: Split String
Posted by: George Enciu
Date: April 12, 2007 04:29AM

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.

Options: ReplyQuote


Subject
Written By
Posted
March 27, 2006 10:10AM
Re: Split String
April 12, 2007 04:29AM
December 17, 2007 09:46AM
February 20, 2008 12:29PM
January 14, 2009 02:22PM
w c
January 29, 2009 10:05PM
March 18, 2009 03:13AM
January 24, 2008 06:17PM
March 04, 2008 08:50AM
August 23, 2008 04:33PM
January 14, 2009 01:40PM
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.