delimiter //
drop function initcap//
create function initcap(ss varchar(1000)) returns varchar(1000)
begin
declare lena int;
declare pos int;
declare firsta char(1);
declare seconda varchar(999);
declare tmpstr varchar(1000);
declare retstr varchar(1000);
if (length(trim(ss)) = 0) then
return '';
end if;
if (right(ss,1) != ' ') then
set ss=concat(ss,' ');
end if;
set pos=instr(ss,' ');
set lena=length(ss);
while (pos > 0) do
set tmpstr=trim(left(ss,pos));
set ss = right(ss,lena - pos );
set lena = length(tmpstr);
set firsta = upper(left(tmpstr,1));
set seconda = lower(right(tmpstr,lena - 1));
if (length(retstr) > 0) then
set retstr = concat(retstr,' ',firsta,seconda);
else
set retstr = concat(firsta,seconda);
end if;
set pos = instr(ss,' ');
set lena = length(ss);
end while;
return retstr;
end;
//
delimiter ;

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()