I can specify that table columns are NOT NULL, but how do I make a stored procedure or function only be compatible with non-null arguments? Adding NOT NULL after the argument name doesn't work.
You would need to validate passed parameter values yourself. If you're using MySQL 5.5 and up you can make use of SIGNAL.
DELIMITER //
CREATE PROCEDURE my_procedure (IN param1 INT)
BEGIN
IF param1 IS NULL THEN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'NULL is not allowed.';
END IF;
-- do whatever
END//
DELIMITER ;
Here is a SQLFiddle demo
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