2011-06-03 45 views
3

我们可以做与INITCAP()功能相反的功能吗?它将每个单词的第一个字母设置为小写字母,其余字母设置为大写字母。例如,SOMEFUNCTION(abc)返回aBCINITCAP的相反功能()

回答

2

以下您可以找到MySQL的功能。

delimiter // 
create function lower_first (input varchar(255)) 
returns varchar(255) 
deterministic 
begin 
declare len int; 
declare i int; 
set len = char_length(input); 
set input = upper(input); 
set i = 0; 
while (i < len) do 
    if (mid(input,i,1) = ' ' or i = 0) then 
     if (i < len) then 
      set input = concat(
          left(input,i), 
          lower(mid(input,i + 1,1)), 
          right(input,len - i - 1) 
         ); 
     end if; 
    end if; 
    set i = i + 1; 
end while; 
return input; 
end; // 
delimiter ; 

select lower_first('this is my TeSt'); -- tHIS iS mY tEST