创建方法如下:
CREATE FUNCTION `get_touid`(`m_auid` bigint,`plid` bigint) RETURNS bigint(20)
BEGIN
declare x1 bigint(20) default '0';
declare pm_authorid bigint(20) default '0';
declare pm_touid bigint(20) default '0';
set @m_auid = m_auid;
set @plids = plid;
#SELECT @pm_authorid :=authorid,@pm_touid :=touid from pm_list where pm_list.plid = @plids ;
SELECT authorid,touid into @pm_authorid , @pm_touid from pm_list where pm_list.plid = @plids ;
if @m_auid = @pm_authorid THEN
set @x1 = @pm_touid;
ELSE
set @x1 = @pm_authorid;
END IF;
return @x1;
END
1、变量赋值方法 set @x1 = ? 或 select @x1 := ?
2、在查询语句select的应用过程中,where条件语句需要添加表名,否则where条件无效。
3、通过 select into 进行变量赋值。
注: 好好学习MySQL,天天向上。