MySQL Forums :: Microsoft SQL Server :: Split String

Advanced Search

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

here is a sample



CREATE PROCEDURE `split`(input text, delim VARCHAR(10))

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;


Edited 1 time(s). Last edit at 04/12/2007 04:30AM by George Enciu.

Options: ReplyQuote

Subject Written By Posted
Split String Mike Sheldon 03/27/2006 10:10AM
Re: Split String George Enciu 04/12/2007 04:29AM
Re: Split String Amnon Levav 12/17/2007 09:46AM
Re: Split String Jeff Tanner 02/20/2008 12:29PM
Re: Split String jim smith 01/14/2009 02:22PM
Re: Split String w c 01/29/2009 10:05PM
Re: Split String Miljan Radovic 03/18/2009 03:13AM
Re: Split String Tim Henderson 01/24/2008 06:17PM
Re: Split String sakthi murugan 03/04/2008 08:50AM
Re: Split String anci wasim 08/23/2008 04:33PM
Re: Split String jim smith 01/14/2009 01:40PM
Re: Split String usha rani 09/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.