MySQL String函数等效于PHP ucwords()函数

编程入门 行业动态 更新时间:2024-10-18 18:16:22
本文介绍了MySQL String函数等效于PHP ucwords()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: MySQL-在现有表格中将每个单词的首字母大写

Possible Duplicate: MySQL - Capitalize first letter of each word, in existing table

是否存在与PHP ucwords() 函数等效的MySQL String函数.

Is there a MySQL String function equivalent to PHP ucwords() function.

最终目标是使用MySQL将字符串中每个单词的首字母大写.

The end goal is to use MySQL to uppercase the first letter of each word in a string.

示例.

-- The name field in the table holds "JOHN DOE" SELECT LOWER(name) FROM table

这将给我结果'john doe'

我希望结果为'John Doe'

推荐答案

本文向您展示了如何在MySQL中定义适当的情况:适当的情况.

This article shows you how to define a Proper Case in MySQL: Proper Case.

包含链接腐烂的情况:

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(18) DEFAULT ' ()[]{},.-_\'!@;:?/'; -- David Rabby & Lenny Erickson added \' SET s = LCASE( str ); WHILE i <= LENGTH( str ) DO -- Jesse Palmer corrected from < to <= for last char 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 ; select proper("d'arcy"); +------------------+ | proper("d'arcy") | +------------------+ | D'Arcy | +------------------+

更多推荐

MySQL String函数等效于PHP ucwords()函数

本文发布于:2023-05-28 06:56:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/315133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file &#039;D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!