mysql – Procedura – ukázka
CREATE DEFINER=`autor`@`localhost` PROCEDURE `proc_wpfb_kategorie`(IN `in_cat_id` INT, OUT `kategorie` VARCHAR(255))
begin
declare loc_cat_id INT DEFAULT 0;
declare loc_cat_parent INT DEFAULT 999999;
declare kategorie_temp varchar (255) default “;
set loc_cat_id = in_cat_id;
select cat_name
from wp_wpfb_cats
where cat_id = loc_cat_id
into kategorie;
delej: WHILE loc_cat_parent > 0 DO
select cat_parent
from wp_wpfb_cats
where cat_id = loc_cat_id
into loc_cat_parent;
if loc_cat_parent = 0 then
leave delej;
end if;
select cat_name
from wp_wpfb_cats
where cat_id = loc_cat_parent
into kategorie_temp;
set loc_cat_id = loc_cat_parent;
set kategorie = concat(kategorie_temp, ‚ | ‚, kategorie);
end while delej;
end