比较MySQL中的变量并将结果保存到其他变量中

时间:2014-04-24 15:04:05

标签: mysql

我在循环中有3 variables

这些变量正在改变他的价值,我想比较它,如果3 variables中的值相同。

我想将其保存到其他变量和insert into表中。 我现在拥有它,我只是在代码中添加了许多更改:

CREATE PROCEDURE getFiltrado(pabellon INT)
BEGIN
DECLARE vcodigo1 INT;
DECLARE vcodigo2 INT;
DECLARE vcodigo3 INT;
DECLARE cursor12 CURSOR FOR SELECT codigo FROM TEMP3;
DECLARE cursor13 CURSOR FOR SELECT codigo FROM TEMP4;
DECLARE cursor14 CURSOR FOR SELECT codigo FROM TEMP5;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET @fin=1;
DROP TABLE IF EXISTS TEMP6;
CREATE TABLE TEMP6(codigo INT);
SET @fin=0;
OPEN cursor12;
    cursor12_loop: LOOP
        FETCH cursor12 INTO vcodigo1;
        IF @fin=1 THEN
            LEAVE cursor12_loop;
        END IF;
        SET @co1=vcodigo1;
        OPEN cursor13;
            cursor13_loop: LOOP
                FETCH cursor13 INTO vcodigo2;
                IF @fin=1 THEN
                    LEAVE cursor13_loop;
                END IF;
                SET @co2=vcodigo2;
                OPEN cursor14;
                    FETCH cursor14 INTO vcodigo3;
                    IF @fin=1 THEN
                        LEAVE cursor14_loop;
                    END IF;
                    SET @co3=vcodigo3;

                       /* IF @co1=@co2=@co3 THEN
                            INSERT INTO TEMP6 VALUES(@co1);
                        END IF;*/ /*Here I try to compare the variables and it doesn't work*/
                    END LOOP cursor14_loop;
                CLOSE cursor14;
            END LOOP cursor13_loop;
        CLOSE cursor13;
    END LOOP cursor12_loop;
CLOSE cursor12;
END;$$

0 个答案:

没有答案