DELIMITER $$
DROP PROCEDURE IF EXISTS `pawn`.`simpleproc`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `pawn`.`simpleproc`(OUT param1 int, inout incr int)
BEGIN
declare incr Integer;
set incr= incr+1;
SELECT count(*) into param1 FROM pawnamount;
END $$
这是我创建存储过程的代码....它已创建.. 执行..
call simpleproc(@param1,@incr);
select @param1,@incr
结果将是空值..这是一个简单的..我已经尝试了很多次。但是,我只得到空值..
答案 0 :(得分:1)
DECLARE incr INT; -- incr is NULL here, add DEFAULT 0 if you want it to have a value SET incr = incr + 1 -- NULL + 1 is still NULL SELECT COUNT(*) INTO param1 FROM pawnamount; -- If the table pawnamount is empty, it generates an empty set, which in a parameter assignment becomes NULL.
答案 1 :(得分:1)
由于您将incr
定义为INOUT
参数,因此不应在程序正文中再次声明它。这样,只要在传递给程序之前初始化它,就可以正确地增加它。
以下是代码:
DELIMITER $$
DROP PROCEDURE IF EXISTS `pawn`.`simpleproc`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `pawn`.`simpleproc`(OUT param1 int, inout incr int)
BEGIN
set incr= incr+1;
SELECT count(*) into param1 FROM pawnamount;
END $$
DELIMITER ;
set @incr = 0;
call simpleproc(@param1,@incr);
select @param1,@incr;