试图从mysql存储过程中获取Count单值

时间:2014-04-18 15:15:38

标签: mysql stored-procedures

我正在尝试在mysql存储过程中进行计数但是无法正确获取语法help1

    delimiter//
create procedure get_count_workmen_type(
    IN employee_payroll int,    
    OUT mycount int
)


begin 

SELECT count(*) into mycount from workman
where employee_payroll = employee_payroll

end //
delimiter;

1 个答案:

答案 0 :(得分:1)

您应该在参数名称前加上(我个人使用" p _"),以区别于列名等。例如,where employee_payroll = employee_payroll将始终为真,因为它比较了专栏本身。

此外,您应该在select语句的末尾添加一个分号。

将这两个更改放在一起可以得到如下内容:

delimiter //

create procedure get_count_workmen_type(
    IN p_employee_payroll int,    
    OUT p_mycount int
)
begin 
  SELECT count(*) 
  into p_mycount 
  from workman
  where employee_payroll = p_employee_payroll;
end //

delimiter ;