一个简单的mysql存储函数

delimiter //
CREATE  FUNCTION concat_char (dec1 char(20),dec2 char(20))
returns char(50)

return concat(dec1,dec2);

//

http://dev.mysql.com/doc/refman/5.1/zh/stored-procedures.html#create-procedure
-------------------------------------------------------

delimiter //
CREATE  FUNCTION SETTOPERC2 (dec1 char(20),dec2 char(20))
returns char(50)
begin
DECLARE Result char(50);
SET Result = '';
if ifnull(dec1,0)=0 or ifnull(dec2,0)=0 then 
      Result='0';
elseif dec1>=dec2 then
      Result='100';
else
      Result = round(dec1 / dec2 * 100, 2);
      if substr(Result,0,1)='.' then
         Result =concat('0',Result);
      end if;
end if;
Result =concat(Result,'%');
return (Result);
end //

你可能感兴趣的:(mysql)