dimanche 31 mai 2020

How to compare the variable which can be existed or null in MYSQL? [duplicate]

I am encountering an issue which is how to do comparison in where clause with the variable can be existed or null. I know there is a operator <=> can do that. But any other method can achieve the same result as <=>. My sample sp is as below. You can imagine I have a model for storing the number of fruit in each store. But the store name can be null which stands for the warehouse. So, the a_store_name can be really a store name or null, simply use = will throw error where there is comparing with null.

Sp:

CREATE PROCEDURE `sp_check_fruit`(IN a_store_name varchar(20))
sp:BEGIN
select fruit number
into number
from fruit
where store_name = a_store_name;
END

Aucun commentaire:

Enregistrer un commentaire