简体   繁体   中英

Opposite function of INITCAP()

Can we do the opposite of the INITCAP() function? It sets the first letter of each word to lowercase and rest of the letters to upper case.

For example, SOMEFUNCTION(abc) returns aBC .

Below you can find a function for 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM