mysql 自定義方法創建 問題總結

創建方法如下:

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,天天向上。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章