2010-10-28 25 views

回答

1

您可以使用:

UPDATE `table` SET 
`field` = CONCAT(UPPER(LEFT(`field`, 1)), LOWER(SUBSTRING(`field`, 2))) 

但你仍然需要對其進行修改,以允許像City下一個單詞大寫字母...

來源here

UPDATE : 找到this在MySQL的論壇的例子,它正是你所需要的:

DROP FUNCTION IF EXISTS proper; 
SET GLOBAL log_bin_trust_function_creators=TRUE; 
DELIMITER | 
CREATE FUNCTION proper(str VARCHAR(128)) 
RETURNS VARCHAR(128) 
BEGIN 
    DECLARE c CHAR(1); 
    DECLARE s VARCHAR(128); 
    DECLARE i INT DEFAULT 1; 
    DECLARE bool INT DEFAULT 1; 
    DECLARE punct CHAR(17) DEFAULT '()[]{},[email protected];:?/'; 
    SET s = LCASE(str); 
    WHILE i < LENGTH(str) DO 
    BEGIN 
     SET c = SUBSTRING(s, i, 1); 
     IF LOCATE(c, punct) > 0 THEN 
     SET bool = 1; 
     ELSEIF bool=1 THEN 
     BEGIN 
      IF c >= 'a' AND c <= 'z' THEN 
      BEGIN 
       SET s = CONCAT(LEFT(s,i-1),UCASE(c),SUBSTRING(s,i+1)); 
       SET bool = 0; 
      END; 
      ELSEIF c >= '0' AND c <= '9' THEN 
      SET bool = 0; 
      END IF; 
     END; 
     END IF; 
     SET i = i+1; 
    END; 
    END WHILE; 
    RETURN s; 
END; 
| 
DELIMITER ;