MySQL函数调用 [英] Mysql function call

查看:78
本文介绍了MySQL函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我多次调用一个函数,那么它将执行一次还是仅执行一次,然后在几次之后使用该值? 示例:

If I call a function several time then will it execute every time or just execute once and the value will be used then after several time? Example:

 select my_function('filed'),my_function('filed')/field2, 
        (my_function('filed')*field1)/field3,
...... from my_table    where group by filed1;

我的问题是my_function('filed')将执行一次,然后结果将在my_function('filed')/field2(my_function('filed')*field1)/field3中使用,或者每次my_function('filed')在系统级被调用并执行?

My question is my_function('filed') will be executed once and then the result will be used in my_function('filed')/field2 and (my_function('filed')*field1)/field3 or every time my_function('filed') will be called and executed in system level ?

推荐答案

为什么不使用捕获函数值的变量. 例如:

Why not use a variable that catch the value of your function. For example:

declare var_function (datatype(size)); // just to declare proper data type for your function

set var_function = my_function('filed');

select var_function, var_function/field2, 
        (var_function*field1)/field3,

....from my_table    where group by filed1;

在这种情况下,您将要重用函数结果,而无需重复函数的过程.

in that case, you'll be going to reuse the function result and no need to repeat the process of the function.

这篇关于MySQL函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆