Opposite INITCAP () function

Is it possible to do something opposite to the function INITCAP()? It sets the first letter of each word to lowercase and the rest of the letters to uppercase.

For example, SOMEFUNCTION(abc)returns aBC.

+3
source share
1 answer

Below you can find the MySQL function .

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
+2
source

All Articles