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

后端 未结 11 2200
太阳男子
太阳男子 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 16:07

    This is working for me In My SQL 5.0

          DELIMITER |
           CREATE FUNCTION CamelCase(str VARCHAR(8000))
           RETURNS VARCHAR(8000) 
              BEGIN
                DECLARE result VARCHAR(8000);
                SET str = CONCAT(' ',str,' ');
                SET result = '';
                WHILE LENGTH(str) > 1 DO
                   SET str = SUBSTR(str,INSTR(str,' ')+1,LENGTH(str));
                   SET result = CONCAT(result,UPPER(LEFT(str,1)), LOWER(SUBSTR(str,2,INSTR(str,' ') - 1)) )  ;
                   SET str = SUBSTR(str,INSTR(str,' '),LENGTH(str));  
               END WHILE;
            RETURN result;
          END 
         |
         DELIMITER ;
    

提交回复
热议问题