mardi 27 mai 2014

Issue with Loop in Mysql


Vote count:

0




I am trying to fetch a row like:



2014-05-01 01:01:01.009 S;I;G=89234EFA8C9E;C=N348HS;O=HelloWorld;M=ABCDAJ- Destroy


And I am splitting it by the semicolon and then by '='. It works fine but there is a problem with the Loop. The Loop runs infinitely. I want it to run only 19 times. And if there is no matching case statement for the character I want it to set i=i+1 and continue the Loop. Please help.



getData: LOOP

IF i < 20 THEN

SET temp = SUBSTRING_INDEX(SUBSTRING_INDEX(var, ';', 2+i),';',-1);
select temp;
SET temp2 = SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(var, ';', 2+i),';',-1),'=',-1);
SET char_key = SUBSTRING_INDEX(temp,'=',1);
select char_key;

SET i = i+1;

CASE char_key
WHEN 'G' THEN SELECT temp2 into GUID;
select GUID;
WHEN 'C' THEN SELECT temp2 into Container;
select Container;
WHEN 'P' THEN SELECT temp2 into Programmer;
select Programmer;
WHEN 'A' THEN SELECT temp2 into UserAgent;
select UserAgent;
WHEN 'B' THEN SELECT temp2 into Benefactor;
select Benefactor;
WHEN 'E' THEN SELECT temp2 into ElapsedTime;
select ElapsedTime;
WHEN 'F' THEN SELECT temp2 into Foundation;
select Foundation;
WHEN 'M' THEN SELECT temp2 into Message;
select Message;
WHEN 'O' THEN SELECT temp2 into ServiceOp;
select ServiceOp;
WHEN 'R' THEN SELECT temp2 into Referrer;
select Referrer;
WHEN 'S' THEN SELECT temp2 into SessionID;
select SessionID;
WHEN 'T' THEN SELECT temp2 into Target;
select Target;
WHEN 'U' THEN SELECT temp2 into UserName;
select UserName;
WHEN 'W' THEN SELECT temp2 into WorkTime;
select WorkTime;
WHEN 'I' THEN SELECT temp2 into SourceIP;
select SourceIP;
ELSE
begin
end;
END CASE;
END IF;
END LOOP;


asked 2 mins ago

Sindu_

255





Aucun commentaire:

Enregistrer un commentaire