Guest User

Untitled

a guest
Oct 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.72 KB | None | 0 0
  1. drop function if exists ucfirst;
  2. drop function if exists ucwords;
  3.  
  4. create function ucfirst (string varchar(1024)) returns varchar(1024)
  5. return concat(upper(substring(string, 1, 1)), lower(substring(string, 2)));
  6.  
  7. delimiter #
  8. create function ucwords (input varchar(1024)) returns varchar(1024)
  9. begin
  10.     set @input := input;
  11.     set @output := "";
  12.     tokenizer: loop
  13.         set @idx := LOCATE(" ", @input);
  14.         if @idx = 0 then
  15.             set @output := concat(@output, ucfirst(@input));
  16.             leave tokenizer;
  17.         end if;
  18.         set @output := concat(@output, ucfirst(substring(@input, 1, @idx)));
  19.         set @input := substring(@input, @idx + 1);
  20.     end loop tokenizer;
  21.     return @output;
  22. end#
  23. delimiter ;
  24.  
  25. select ucwords("UNITED states Of AmERIca");
Add Comment
Please, Sign In to add comment