2012-12-30 15 views
2

如何爲MySQL存儲過程添加具有NULL缺省值的參數?爲MySQL存儲過程添加具有NULL缺省值的參數

+0

' when'可以使用的情況。發佈你已經嘗試過的請。 – bonCodigo

+0

我試圖添加它,但它不工作,thanx –

+0

重複:http://stackoverflow.com/questions/12652241/writing-optional-parameters-within-stored-procedures-in-mysql –

回答

1

根據this answer MySQL不支持函數或存儲過程中的「默認參數」。

This answer在同一頁面上提供了一個可能適用於您的解決方案。

0

具有可變和任何查詢 'case`: -

BEGIN 
    DECLARE @NullValue:=Null; 
    SELECT 
    CASE WHEN Sum(myField) Is Null 
    THEN @NullValue ELSE Sum(myField) 
    END AS Total 
    FROM table_name; 
END 
;