如何用MySQL实现INITCAP()功能的反面?
该INITCAP()
方法以大写形式显示每个单词的第一个字符,以小写形式显示其余字符。
要实现相反的功能,您需要在MySQL中创建自己的功能。这是功能-
mysql> delimiter // mysql> create function convertFirstLetterToLowerAndRemainingToCapital(value varchar(250)) returns varchar(250) deterministic begin declare valueLength int; declare l int; set valueLength = char_length(value); set value = upper(value); set l = 0; while (l < valueLength ) do if (mid(value,l ,1) = ' ' or l = 0) then if (l < valueLength ) then set value= concat( left(value,l), lower(mid(value,l+ 1,1)), right(value,valueLength - l - 1) ); end if; end if; set l = l + 1; end while; return value; end; // mysql> delimiter ;
借助select语句调用函数-
mysql> select convertFirstLetterToLowerAndRemainingToCapital('Introduction To MySQL');
这将产生以下输出-
+-------------------------------------------------------------------------+ | convertFirstLetterToLowerAndRemainingToCapital('Introduction To MySQL') | +-------------------------------------------------------------------------+ | iNTRODUCTION tO mYSQL | +-------------------------------------------------------------------------+ 1 row in set, 2 warnings (0.04 sec)