SQL语句可以用变量代替吗?


select type,price from gree where price between 3000 and 5000;

想定义一个自定义函数,用变量x,y代替3000,5000。但是这么写的话编译会报错,想请问下正确的应该怎么代替?

可以写成这样的


 create
        function myfun_getMax(num1 int, num2 int)
        returns int        
    begin
        declare res int;
 
    select type,price from gree where price between num1 and num2 ;
     
        return res;
    end;

自定义函数,输入两个变量xy,得出一个结果,xy可以赋值3000,5000,这个是可以办到的啊。