Is there a simple way to convert MySQL data into Title Case?

后端 未结 11 2202
太阳男子
太阳男子 2020-11-27 15:35

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 Darin

11条回答
  •  北海茫月
    2020-11-27 15:49

    Woo! I'm not handy with SQL at all; Here's the method that worked for me:

    1. Export the table as a text file in .sql format.
    2. Open the file in Textmate (which I already had handy).
    3. Select the rows with UPPERCASE data.
    4. Choose "Convert" from the "Text" menu, and select "to Titlecase".
    5. Find and replace each instance of:

      INSERT INTO `Table` (`Col1`, `Col2`, `Etc`, ...) VALUES
      

      with the correct lowercase values.

    6. Import the table back into the database.
    7. Use UPDATE table SET colname=LOWER(colname); to reset lowercase values for the columns that should be lowercase.

    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!

提交回复
热议问题