Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL Chain Select-Abfrage

Ich versuche es einfach mit der Schleifenstruktur in Mysql und habe Erfolg. Nur zum Teilen posten--

CREATE PROCEDURE `root_connect`(IN init char(1),OUT str char(15))
BEGIN
    set @startChar:=(select connector from tableName where root = init);
    set @endloop := "no";
    set @fullchar:= @startChar;
    set @newchar:= "";  
    if (@startChar !="-" OR @startChar =null) then 
        WHILE (@endloop = "no") DO                  
            set @newchar :=(select connector from tableName where root = @startChar);       
            if(@newchar = '-') THEN
                set @endloop := "yes";
            else
                set @fullchar:= concat(@fullchar,"-",@newchar);
            end if;         
            set @startChar := @newchar;     
        END WHILE;
    end if;
        select @fullchar;
END