1:函数名称
2:形参名称以及类型
3:返回值
4:定义变量:declare、default:默认值
5.查询结果赋值变量
6.返回变量
CREATE DEFINER=root
@%
FUNCTION Get_StationInfoByTrunkID
(xxid
int,instationid
int,instationtype
int) RETURNS varchar(60) CHARSET gbk
BEGIN
declare stationname varchar(255) default “”;
declare xxstationid int;
if(xxid>0) then
select Of_Station_ID into xxstationid from table1 where Dev_ID=xxid limit 1;
if(xxstationid>0) then
select Description into stationname from table2 where Dev_ID=xxstationid limit 1;
end if;
else
if(instationid>0 and instationtype >0) then
return Get_OfStationName(instationtype,instationid);
end if;
end if;
return stationname;
RETURN ‘’;
END