Posted By

ping_ch on 01/26/09


Tagged

mysql sql capitalize


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

robksawyer


MySQL Capitalize


 / Published in: MySQL
 

  1. DELIMITER $$
  2. CREATE FUNCTION CAP_FIRST (input VARCHAR(255))
  3.  
  4. RETURNS VARCHAR(255)
  5.  
  6. DETERMINISTIC
  7.  
  8. BEGIN
  9. DECLARE len INT;
  10. DECLARE i INT;
  11.  
  12. SET len = CHAR_LENGTH(input);
  13. SET input = LOWER(input);
  14. SET i = 0;
  15.  
  16. WHILE (i < len) DO
  17. IF (MID(input,i,1) = ' ' OR i = 0) THEN
  18. IF (i < len) THEN
  19. SET input = CONCAT(
  20. LEFT(input,i),
  21. UPPER(MID(input,i + 1,1)),
  22. RIGHT(input,len - i - 1)
  23. );
  24. END IF;
  25. END IF;
  26. SET i = i + 1;
  27. END WHILE;
  28.  
  29. RETURN input;
  30. END$$
  31.  
  32. DELIMITER ;

Report this snippet  

You need to login to post a comment.