MYSQL过程没有被调用

时间:2019-03-07 18:09:40

标签: mysql sql mysql-workbench

被调用后的以下过程显示错误“结果返回多行”,其中给定的输入值只是一个参数。

    DELIMITER $$
    CREATE PROCEDURE p( IN en int,OUT ename int, OUT incr_sal int, OUT s_sal 
    int, OUT count1 int)
    BEGIN

    DECLARE sal INT DEFAULT 0; 
    DECLARE cnt int DEFAULT 0; 
    DECLARE emp_name int DEFAULT 0;

    SELECT `ename`,`salary` INTO sal, emp_name 
    FROM works w 
    WHERE `ename`=en;

    SELECT COUNT(m.empname) INTO cnt 
    FROM manages m 
    WHERE m.empname=en 
    GROUP BY m.empname;

    SET @ename=emp_name; SET @incr_sal=sal;

    IF sal>50000 && cnt>2 THEN SET sal=sal+((sal*5)/100);
       ELSEIF sal>50000 && sal<60000 && cnt>=1 THEN SET sal=sal+((sal*2)/100);
       ELSEIF sal>10000 && cnt=0 THEN SET sal=sal+((sal*1)/100);
    end IF;

    SET @s_sal=sal; 
    SET @count1=cnt;

    SELECT @ename,@incr_sal,@s_sal,@count1;
    END $$
    DELIMITER ;

    CALL p('Sam',@ename,@incr_sal,@s_sal,@cnt);

1 个答案:

答案 0 :(得分:1)

分别执行查询并查看结果

SELECT `ename`,`salary` INTO sal, emp_name 
FROM works w 
WHERE `ename`=en;

您是否期望这里有多行还是只有一排。如果期望一个,则只需将限制1添加为:

 SELECT `ename`,`salary` INTO sal, emp_name 
FROM works w 
WHERE `ename`=en limit 1;