MySQL Capitalize


/ Published in: MySQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. DELIMITER $$
  2. CREATE FUNCTION CAP_FIRST (input VARCHAR(255))
  3.  
  4.  
  5.  
  6. DECLARE len INT;
  7.  
  8. SET len = CHAR_LENGTH(input);
  9. SET input = LOWER(input);
  10. SET i = 0;
  11.  
  12. WHILE (i < len) DO
  13. IF (MID(input,i,1) = ' ' OR i = 0) THEN
  14. IF (i < len) THEN
  15. SET input = CONCAT(
  16. LEFT(input,i),
  17. UPPER(MID(input,i + 1,1)),
  18. RIGHT(input,len - i - 1)
  19. );
  20. SET i = i + 1;
  21. END WHILE;
  22.  
  23. RETURN input;
  24. END$$
  25.  
  26. DELIMITER ;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.