如何将每个单词的第一个字母中的所有数据从大写转换并更新为大写?
需要使用新值更新数据库。
由于
答案 0 :(得分:7)
看起来有人为此创建了一个函数,
CREATE FUNCTION CAP_FIRST (input VARCHAR(255))
RETURNS VARCHAR(255)
DETERMINISTIC
BEGIN
DECLARE len INT;
DECLARE i INT;
SET len = CHAR_LENGTH(input);
SET input = LOWER(input);
SET i = 0;
WHILE (i < len) DO
IF (MID(input,i,1) = ' ' OR i = 0) THEN
IF (i < len) THEN
SET input = CONCAT(
LEFT(input,i),
UPPER(MID(input,i + 1,1)),
RIGHT(input,len - i - 1)
);
END IF;
END IF;
SET i = i + 1;
END WHILE;
RETURN input;
END;
SELECT CAP_FIRST(
'this is totally like @ TEST 1 right!'
)
返回:“这完全像@ Test 1 Right!”
链接:http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/
答案 1 :(得分:0)
这可能会有所帮助......
http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/
根据FAngel评论,如果链接死亡,我完全抄袭了这里的内容:
CREATE FUNCTION CAP_FIRST (input VARCHAR(255))
RETURNS VARCHAR(255)
DETERMINISTIC
BEGIN
DECLARE len INT;
DECLARE i INT;
SET len = CHAR_LENGTH(input);
SET input = LOWER(input);
SET i = 0;
WHILE (i < len) DO
IF (MID(input,i,1) = ' ' OR i = 0) THEN
IF (i < len) THEN
SET input = CONCAT(
LEFT(input,i),
UPPER(MID(input,i + 1,1)),
RIGHT(input,len - i - 1)
);
END IF;
END IF;
SET i = i + 1;
END WHILE;
RETURN input;
END;
So running the following code...
SELECT CAP_FIRST(
'this is totally like @ TEST 1 right!'
)
答案 2 :(得分:0)
您可以执行以下操作:
http://www.thingy-ma-jig.co.uk/blog/30-09-2010/mysql-how-upper-case-words
首先如图所示定义函数,然后运行更新语句:
UPDATE table SET someColumn = UC_FIRST(someColumn);