Create a function with optional arguments in MySQL

后端 未结 3 628
我在风中等你
我在风中等你 2020-12-17 08:57

I want to create a function with optional arguments in MySQL. For instance, I want to create function that calculates the average of its arguments. I create a function of fi

3条回答
  •  没有蜡笔的小新
    2020-12-17 09:57

    Another approach is to pass only one 'super' parameter which is string with commas in it separating the real parameters. The mysql procedure can then parse the 'super' parameter into the separate real parameters. Example:

    create procedure procWithOneSuperParam(param1 varchar(500))
    declare param2 varchar(100);
    begin
     if LOCATE(',',param1) > 0 then
      .. param2= ..
    

提交回复
热议问题