Erro ao Criar FUnction MYSQL
Tenho a tabela cliente com dois campos cliente_id e cliente_pai...
e preciso usar esta function pra retorna alguns dados....
mais a function Esta errada da um erro na query....
alguem pode informar o erro?
CREATE FUNCTION cliente.idCliente (ID INT) RETURNS VARCHAR(255)
BEGIN
DECLARE x INT;
DECLARE str VARCHAR(255);
DECLARE sqls VARCHAR(255);
SET x = 0;
SET str = '';
SET sqls = ID;
WHILE x < 100 DO
case x
when 0 then sqls = CONCAT('SELECT id_cliente FROM `cliente` where cliente_pai = ', sqls)
when 1 then sqls = CONCAT('UNION ALL', 'SELECT id_cliente FROM `cliente` where cliente_pai IN (',sqls,')')
else sqls = CONCAT('UNION ALL', 'SELECT id_cliente FROM `cliente` where cliente_pai IN (',sqls,')')
end;
SET x = x + 1;
if NOT EXISTS(EXECUTE(sqls)){
RETURN sqls;
}
END WHILE;
END;Discussão (1)
Carregando comentários...