有没有一种简单的方法可以将 MySQL 数据转换为 Title Case?
我有一个 MySQL 表,其中一列中的所有数据都以大写形式输入,但我需要转换为标题大小写,并识别类似于 大胆的火球标题案例脚本.
I have a MySQL table where all the data in one column was entered in UPPERCASE, but I need to convert in to Title Case, with recognition of "small words" akin to the Daring Fireball Title Case script.
我发现了这个优秀的解决方案 用于将字符串转换为小写,但 Title Case 函数似乎已被排除在我的 MySQL 版本之外.有没有一种优雅的方法来做到这一点?
I found this excellent solution for transforming strings to lowercase, but the Title Case function seems to have been left out of my version of MySQL. Is there an elegant way to do this?
推荐答案
哇!我根本不擅长 SQL;这是对我有用的方法:
Woo! I'm not handy with SQL at all; Here's the method that worked for me:
- 将表导出为 .sql 格式的文本文件.
- 在 Textmate(我已经手头上)中打开文件.
- 选择包含大写数据的行.
- 从文本"菜单中选择转换",然后选择到标题框".
查找并替换以下各项的每个实例:
- Export the table as a text file in .sql format.
- Open the file in Textmate (which I already had handy).
- Select the rows with UPPERCASE data.
- Choose "Convert" from the "Text" menu, and select "to Titlecase".
Find and replace each instance of:
INSERT INTO `Table` (`Col1`, `Col2`, `Etc`, ...) VALUES
使用正确的小写值.
我之前没有尝试使用 Textmate 的原因是我无法弄清楚如何在不破坏其他数据的情况下将单个列转换为 Title Case,但这种方法似乎有效.感谢您的指导和支持!
The reason I didn't try using Textmate before was that I couldn't figure out how to convert a single column to Title Case without ruining the other data, but this method seems to work. Thanks for your guidance and support!
相关文章