gpt4 book ai didi

mysql函数调用

转载 作者:可可西里 更新时间:2023-11-01 06:57:40 25 4
gpt4 key购买 nike

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

 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') 都会在系统级调用和执行?

最佳答案

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

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;

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

关于mysql函数调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14356694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com