为 MySQL 存储过程添加默认值为 NULL 的参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14091073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding parameters with NULL default value for MySQL stored procedure
提问by Raed Alsaleh
How can I add parameters with NULL default value for MySQL stored procedure?
如何为 MySQL 存储过程添加默认值为 NULL 的参数?
采纳答案by losthorse
According to this answerMySQL does not support true 'default parameters' in functions or stored procedures.
根据此答案,MySQL 不支持函数或存储过程中的真正“默认参数”。
This answeron the same page provides a solution that may work for you.
同一页面上的此答案提供了可能适合您的解决方案。
回答by bonCodigo
Any query with variable and 'case`:-
任何带有变量和“case”的查询:-
BEGIN
DECLARE @NullValue:=Null;
SELECT
CASE WHEN Sum(myField) Is Null
THEN @NullValue ELSE Sum(myField)
END AS Total
FROM table_name;
END
;