創建方法如下:
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,天天向上。