mysql delimiter的说明

默认情况下,mysql解释器一遇到分号(;),它就要自动执行。 
不会等到用户把这些语句全部输入完之后,再执行整段语句。 

而自定义函数和存储过程的SQL语句有好多行,且语句中包含有分号,
为了保证整段语句的整体执行,就要使用delimiter,更改mysql的默认结束符。 

 

 

再看一个列子:

delimiter $$

use `test`$$

drop function if exists `queryOnePartnerInviteCodeByCode`$$

create function `queryOnePartnerInviteCodeByCode`(_code varchar(4000)) returns varchar(4000) charset utf8
begin
set _code=TRIM(_code);

if _code is null or _code='' then
return null;
end if ;

select GROUP_CONCAT(id) into @__userID from lcs_member where del_flag=0 and invite_code=_code;
if @__userID is null or @__userID='' then
return null;
end if ;


select GROUP_CONCAT(id),GROUP_CONCAT(invite_code) into @__selectTmpID,@_invite_code from lcs_member where del_flag=0 and invite_code!='' and invite_code is not null and belong_to_partner>0 and FIND_IN_SET(belong_to_partner,@__userID)>0;
if (@__selectTmpID!='' and @__selectTmpID is not null ) then
return @_invite_code;
else
return null;
end if;

end$$

delimiter;

posted @ 2019-01-04 15:25  邱明成  阅读(2502)  评论(0编辑  收藏  举报