MySQL Proper Case Function


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



Copy this code and paste it in your HTML
  1. SET GLOBAL log_bin_trust_function_creators=TRUE;
  2. DELIMITER |
  3. CREATE FUNCTION proper( str VARCHAR(128) )
  4. DECLARE c CHAR(1);
  5. DECLARE s VARCHAR(128);
  6. DECLARE punct CHAR(17) DEFAULT ' ()[]{},.-_!@;:?/';
  7. SET s = LCASE( str );
  8. WHILE i < LENGTH( str ) DO
  9. SET c = SUBSTRING( s, i, 1 );
  10. IF LOCATE( c, punct ) > 0 THEN
  11. SET bool = 1;
  12. ELSEIF bool=1 THEN
  13. IF c >= 'a' AND c <= 'z' THEN
  14. SET s = CONCAT(LEFT(s,i-1),UCASE(c),SUBSTRING(s,i+1));
  15. SET bool = 0;
  16. END;
  17. ELSEIF c >= '0' AND c <= '9' THEN
  18. SET bool = 0;
  19. END;
  20. SET i = i+1;
  21. END;
  22. END WHILE;
  23. RETURN s;
  24. |
  25. DELIMITER ;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.