I'm trying to check class using MySQL procedure, but the following procedure always returns 0:
DELIMITER //
CREATE PROCEDURE `validate_class`(IN `class` INT)
BEGIN
if(class NOT IN ('A','B','E') ) then
select 1;
else
select 0;
end if;
END //
DELIMITER ;
call test:
call validate_class('G'); //return 0
call validate_class('A'); //return 0
It should return 1 when class isn't (A and B and E), any help?
You have implicit conversions CHAR -> INT -> CHAR.
Change parameter datatype:
CREATE PROCEDURE `validate_class`(IN `class` CHAR(1))
BEGIN
if(class NOT IN ('A','B','E') ) then
select 1;
else
select 0;
end if;
END
SqlFiddleDemo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With