1
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 $$

This is my code to create a stored procedure....It's created.. For execute..

call simpleproc(@param1,@incr);
select @param1,@incr

The Result will be null values.. It is the simple one.. I've tried many times.But,I get null values only..

2 Answers 2

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.
Sign up to request clarification or add additional context in comments.

1 Comment

count(*) will never return NULL. It will return 0 if the table is empty.
1

Since you define incr as an INOUT paramater, you should not declare it again in the body of your procedure. This way you can increment it properly as long as it is initialized before being passed to your procedure.

Here's the code:

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.