Mysql函数模板
原创
©著作权归作者所有:来自51CTO博客作者说文科技的原创作品,请联系作者获取转载授权,否则将追究法律责任
Mysql函数编写模板
1.模板如下:
CREATE FUNCTION fn_get_department_key_by_bnshashcode(v_bns_hash_code varchar(32) , v_date datetime)
RETURNS int(11)
begin
declare ret_key int;
if exists ( sql_one ) then
sql_two
elseif exists(sql_three ) then
sql_four;
elseif exists (sql_five) then
sql_six;
else
sql_seven;
end if;
return ret_key;
end
2.注意
-
function
中的参数是没有in,out
来修饰的
-
function
中返回值语句是没有分号分割的
-
function
中的语句用begin end
围绕
- 是
elseif
,而不是else if
- 除了最后一个
else
之外,都有then
语句