2

我在以下过程中遇到错误

DELIMITER // 

DROP PROCEDURE IF EXISTS getDestaque //

CREATE PROCEDURE getDestaque(
OUT v_id_imovel_1 INT,
OUT v_titulo_1 VARCHAR(200),
OUT v_cidade_1 VARCHAR(120),
OUT v_categoria_1 VARCHAR(100),
OUT v_foto_1 VARCHAR(100),
OUT v_id_imovel_2 INT,
OUT v_titulo_2 VARCHAR(200),
OUT v_cidade_2 VARCHAR(120),
OUT v_categoria_2 VARCHAR(100),
OUT v_foto_2 VARCHAR(100)
)
BEGIN

    SELECT I.id_imovel INTO v_id_imovel_1, 
    I.titulo INTO v_titulo_1, 
    C.cidade INTO v_cidade_1, 
    CAT.categoria INTO v_categoria_1, 
    IFT.foto INTO v_foto_1
    FROM imoveis AS I
    INNER JOIN cidades AS C ON I.id_cidade = C.id_cidade
    INNER JOIN categorias AS CAT ON I.id_categoria = CAT.id_categoria
    INNER JOIN imoveis_fotos AS IFT ON I.id_imovel = IFT.id_imovel AND IFT.principal = 1
    WHERE I.destaque_index = 1
    ORDER BY RAND() LIMIT 1;

    SELECT I.id_imovel INTO v_id_imovel_2, 
    I.titulo INTO v_titulo_2, 
    C.cidade INTO v_cidade_2, 
    CAT.categoria INTO v_categoria_2, 
    IFT.foto INTO v_foto_2
    FROM imoveis AS I
    INNER JOIN cidades AS C ON I.id_cidade = C.id_cidade
    INNER JOIN categorias AS CAT ON I.id_categoria = CAT.id_categoria
    INNER JOIN imoveis_fotos AS IFT ON I.id_imovel = IFT.id_imovel AND IFT.principal = 1
    WHERE I.destaque_index = 1 AND I.id_imovel <> v_id_imovel_1 
    ORDER BY RAND() LIMIT 1;

    UPDATE imoveis SET destaque_index_view = destaque_index_view+1 WHERE id_imovel = v_id_imovel_1 OR id_imovel = v_id_imovel_2;

END
//

DELIMITER ;

不工作,PhpMyAdmin 没有向我显示错误,任何人都可以帮助我吗?

4

1 回答 1

0

INTO对于每个 SELECT 查询,您应该只使用一次关键字。

SELECT value1, value2 INTO out_value1, out_value2 FROM some_table;

这应该有效:

DELIMITER // 

DROP PROCEDURE IF EXISTS getDestaque //

CREATE PROCEDURE getDestaque(
OUT v_id_imovel_1 INT,
OUT v_titulo_1 VARCHAR(200),
OUT v_cidade_1 VARCHAR(120),
OUT v_categoria_1 VARCHAR(100),
OUT v_foto_1 VARCHAR(100),
OUT v_id_imovel_2 INT,
OUT v_titulo_2 VARCHAR(200),
OUT v_cidade_2 VARCHAR(120),
OUT v_categoria_2 VARCHAR(100),
OUT v_foto_2 VARCHAR(100)
)
BEGIN

    SELECT I.id_imovel, I.titulo, C.cidade, CAT.categoria, IFT.foto INTO v_id_imovel_1, 
     v_titulo_1, 
     v_cidade_1, 
     v_categoria_1, 
     v_foto_1
    FROM imoveis AS I
    INNER JOIN cidades AS C ON I.id_cidade = C.id_cidade
    INNER JOIN categorias AS CAT ON I.id_categoria = CAT.id_categoria
    INNER JOIN imoveis_fotos AS IFT ON I.id_imovel = IFT.id_imovel AND IFT.principal = 1
    WHERE I.destaque_index = 1
    ORDER BY RAND() LIMIT 1;

    SELECT I.id_imovel, I.titulo, C.cidade, CAT.categoria, IFT.foto INTO v_id_imovel_2, 
     v_titulo_2, 
     v_cidade_2, 
     v_categoria_2, 
     v_foto_2
    FROM imoveis AS I
    INNER JOIN cidades AS C ON I.id_cidade = C.id_cidade
    INNER JOIN categorias AS CAT ON I.id_categoria = CAT.id_categoria
    INNER JOIN imoveis_fotos AS IFT ON I.id_imovel = IFT.id_imovel AND IFT.principal = 1
    WHERE I.destaque_index = 1 AND I.id_imovel <> v_id_imovel_1 
    ORDER BY RAND() LIMIT 1;

    UPDATE imoveis SET destaque_index_view = destaque_index_view+1 WHERE id_imovel = v_id_imovel_1 OR id_imovel = v_id_imovel_2;

END
//

DELIMITER ;
于 2013-08-29T12:27:15.917 回答