Stored Procedure Optional Parameters

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dhui
Forum Newbie
Posts: 14
Joined: Mon May 10, 2010 1:42 pm

Stored Procedure Optional Parameters

Post by dhui »

Code: Select all

DELIMITER //
CREATE PROCEDURE InsertUserData(IN uEmail VARCHAR(300), IN uPass VARCHAR(60), IN uName TEXT)
BEGIN
	INSERT INTO user (email, pass, name)
	VALUE (uEmail, uPass, uName);  //How do I get it so that it will enter null for uName if no name was given as a parameter?
END //
DELIMITER ;
I am new to mysql stored procedures. Is there a way to set a parameter value to NULL unless the parameter is sent a value? See above create procedure to see what I am trying to do.

Thanks.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Stored Procedure Optional Parameters

Post by mikosiko »

parameters (IN/OUT or INOUT) cannot be omitted when you CALL a procedure no matter what value the parameter has.
Post Reply