Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have a default parameter for a mysql stored procedure?

I have googled this and keep coming up with "No it is not possible" but these posts were dated 2005-2007 so I'm wondering if this has been changed. A code example:

CREATE PROCEDURE `blah` (   myDefaultParam int = 0 -- This breaks the code for some reason ) BEGIN   -- Do something here END 

One of the solutions has been to pass null and then check for null and set the variable. I don't want to do that and I shouldn't have to. If this is true then MySql devs need to wake up because there is so much more I could do with MSSQL.

like image 409
aarona Avatar asked Jun 11 '09 18:06

aarona


People also ask

Can a stored procedure have default values for its parameters?

If you add a parameter when creating a stored procedure, you can provide a default value so that the execution statement is not required to pass input value to this parameter. To provide a default value to a parameter, you should use this format: "@parameter_name data_type = default_value".

Is a default parameter mode in MySQL?

The MySQL Stored procedure parameter has three modes: IN, OUT, and INOUT. When we declare an IN type parameter, the application must pass an argument to the stored procedure. It is a default mode. The OUT type parameter, the stored procedure returns a final output generated by SQL Statements.

What is the default parameter type in stored procedure?

The default is an input parameter. To specify an output parameter, the OUTPUT keyword must be specified in the definition of the parameter in the CREATE PROCEDURE statement. The procedure returns the current value of the output parameter to the calling program when the procedure exits.

Can stored procedure have parameters?

A stored procedure can have a maximum of 2100 parameters specified. Each parameter is assigned a name, a data type, and direction like Input, Output, or Return. If a direction is not specified, then by default, it is Input. You can specify a default value for the parameters.


1 Answers

It's still not possible.

like image 91
Paul Sonier Avatar answered Sep 20 '22 15:09

Paul Sonier