Count () not working properly Mysql PROCEDURE

I created one procedure that takes 2 parameters and checks the counter. But when I pass an ""empty value, it still returns 1 count. I do not understand why it works like that. Thanks for the help below, my procedure

DELIMITER $$

CREATE DEFINER=`dadclient`@`123.63.249.169` PROCEDURE `checkInOut`(IN grid varchar(50),OUT count INT)
begin 

select count(GRIDID) into count  from GRIDID where GRIDID=grid;
select count;

END

when i call

 checkInOut("",@aaa);
             select @aaa;

When I call it, it returns me 1, which is wrong.

+4
source share
2 answers

But when I pass "" an empty value, it still returns 1 count.

Because when you say that it is empty by providing an empty string, that is the value. An empty string is also considered as a value in the database and therefore you get the score as 1

MySQL docs :

COUNT (expression)

-NULL expr SELECT. BIGINT.

, , count 0, "", NULL.

+2

Yo mate, :

DELIMITER $$
CREATE
    DEFINER=`dadclient`@`123.63.249.169`
    PROCEDURE `checkInOut`(
        IN `grid` VARCHAR(50),
        OUT `count` INT
    )
BEGIN
-- insert value into variable
    SET `count` = (
        select count(GRIDID)
        from GRIDID
        where GRIDID=grid;
    );
END$$
DELIMITER ;  

, , . php CALL checkInOut($input, $output);. SELECT... , afaik, count OUT parameter

:

  • GRIDID ? , , WHERE key
  • , , , contain one row. , mate
0

All Articles