I'm learning how to work with MySQL's stored procedures and am getting snowed by error messages that I can't seem to fix. Someone gave me a script to create a stored procedure here. When I paste it into phpMyAdmin > SQL, I got this error message: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 1
Yet it does create a stored procedure - though it doesn't work. At one point, I had one that actually worked, but I haven't been able to recreate it. Another frequent error is 1054 Unknown column (theld). I checked this discussion, but my code is already wrapped in BEGIN/END.
So I wondered if it's possible to do a workaround by simply editing code in phpMyAdmin to make it work. I modified the code to target a different table - gz_life_mammals - also replacing the field Parent with ParentID. (gz_life_mammals already has a text field named Parent).
Now when I go into phpMyAdmin > Procedures > showMammals > Execute, I get the same 1054 error message. If I click Edit routine > Parameters, the values for Direction and Type are IN and INT; everything else is blank.
Is it possible to fix this through phpMyAdmin, or is there a better software program for the job? Sorry for the long explanation.
BEGIN
declare bDoneYet boolean default false;
declare working_on int;
declare next_level int;
declare theCount int;
declare i int;
SET i = 1;
CREATE temporary TABLE xxFindChildenxx
( N int not null,
processed int not null,
level int not null,
ParentID int not null
);
set bDoneYet=false;
insert into xxFindChildenxx (N,processed,level,ParentID) select theId,0,0,0;
while (!bDoneYet) do
select count(*) into theCount from xxFindChildenxx where processed=0;
if (theCount=0) then
set bDoneYet=true;
else
SELECT N,level+1 INTO working_on,next_level FROM xxFindChildenxx where processed=0 limit 1;
insert into xxFindChildenxx (N,processed,level,ParentID)
select N,0,next_level,ParentID
from gz_life_mammals
where parent=working_on;
update xxFindChildenxx set processed=1 where N=working_on;
end if;
end while;
delete from xxFindChildenxx where N=theId;
select level,count(*) as lvlCount from xxFindChildenxx group by level;
drop table xxFindChildenxx;
END