MySQL自定义函数的创建

create definer = current_user function `functioName`('col1' varchar(100),`col2` int(11))
    returns int(11)
BEGIN
    --声明变量1
    DECLARE a int DEFAULT 0;
    --声明变量2 局部变量
    SET b := 2;
    --声明变量3 全局变量
    SET @c := 3;
    --条件判断
    if b=@c then 
        @c := @c+1;
    else if a=c then
        @c := 0;
    else
        @c := 666;
    end if;
    RETURN @c;
END;

 之前对这一块一直不太熟悉,这次用到了顺手保存一下。

函数只能返回单一的值,且不论传入参数和返回参数都必须声明类型和长度,否则报错;

变量声明暂且记了这么几种,大概够用了。

猜你喜欢

转载自blog.csdn.net/dou747172348/article/details/85701855
今日推荐