SQL Solution - Recursive CTE, split string by multiple delimiters and save delimeter
It should be apparent that since this is a II problem, using the I/first iteration of the problem is a good place to start.  Here is a link to that problem as w
It should be apparent that since this is a II problem, using the I/first iteration of the problem is a good place to start.  Here is a [link to that problem](https://leetcode.com/problems/first-letter-capitalization/description/) as well as [my solution](https://leetcode.com/problems/first-letter-capitalization/solutions/6079821/solution-for-all-sql-types-split-string-into-rows-apply-operations-aggregate/).  I\'ll make heavy use of that original solution, with that same process there being used here:\n\\- Split string into token words, through here we have multiple delimters (space and hyphen), and need to store the delimiter along with the token word to properly re-construct the orginal string\n\\- Properly format the token word, by making the first letter uppercase and all subsequent letters lowercase, and here we\'ll also concatenate the delimiter to the formatted word\n\\- Aggregate the formatted words using string aggregation, grouping by the original content (content_text and content_id as per the requirements)\n\nIn my I solution I used an Oracle-specific `CONNECT BY` there, and a recursive CTE for the other 3 SQL types, but here I used a recursive CTE for all 4, which is very similar to the recursive CTE for MySQL, MSSQL, and Postgres in the I solution.  Let\'s dive into how to tackle this II variant...\n\n# Approach\nAs touched on in the intro, the overall process is the same here as in the previous iteration of this problem, and the first CTE is again `content_sep_words`, which splits each delimited `content_text` into its token components.  This recursive CTE is similar to a loop in other programming languages (Python is the main one that I use):\n\\- Find the first delimiter (if at all) in `content_text` and split into `word`, which is what\'s before the delimiter, and `remaining`, which is the rest of the string.\n\\- While delimiters are present in remaining, continue the process, until the entire string has been consumed\n\nNote here that we have two delimiters, the space and the hyphen, which results in some messy `case when` code:\n\\- Since the function that finds the index of a character in a string (`instr()`, `charindex()`, `position()`, etc.) returns 0 if that character is not present, we cannot just use `least()` to get the first instance.  So we\'ll check if either delimiter is present in the string, and ensure that the first of either valid delimiter is used to split the string.\n\\-\\- At a high level, the `case when` statements are used to check the multiple delimiters, and are as follows, using "string" to mean the input string: \n\\-\\-\\- No space or hyphen - the string is `word`, and `remaining` is `\'\'`/`null`\n\\-\\-\\- No space but a hyphen - the delimiter is the first hyphen\n\\-\\-\\- Space but no hyphen - the delimiter is the first space\n\\-\\-\\- Space and hyphen - compare the positions of the first space and hyphen, and use the first (lesser index) of the two\n\\- Since the delimiter varies, here the delimiter is included in the `remaining`.  Take that first character of `remaining` and store it as a new column (`delim`), which will be concatenated later to the formatted word to preserve the correct delimiter.\n\\- Adding to that previous point, the first character of `remaining` will be a delimiter, so consider characters 2 an after (SQL character indexing starts at 1) when searching for the next delimiter\n\nOnce `content_sep_words` has been modified to handle two delimiters and store the respective delimiter and token words, the next CTE `content_sep_words_capitalized` doesn\'t vary much.  Do a simple select (no `where`) from `content_sep_words`, and here the formatting of the word doesn\'t change - first character uppercase and subsequent characters lowercase - but also concatenate the delimiter as a prefix to the word, ensuring that the correct space or hyphen is present.\n\nWhile `content_sep_words` had heavy modifications and `content_sep_words_capitalized` needed some adjustments, the final select needs no modifications.  Since the `formatted_word` field from `content_sep_words_capitalized` now contains the delimiter, use the proper string concatenation grouping to aggregate the component words back into a full string, and since the delimiter is included, the separator will be an empty string (`\'\'`).  For reference, here are the proper aggregation functions to use per SQL type:\nHere\'s those functions per language:\n\\- Oracle: listagg()\n\\- MySQL: group_concat()\n\\- MSSQL: string_agg()\n\\- Postgres: string_agg()\n\n# Code\n```Oracle []\n/* Write your PL/SQL query statement below */\n\nWITH content_sep_words(content_id, content_text, delim, word, remaining, word_level) AS (\n    SELECT\n        content_id,\n        content_text,\n        \'\' as delim,\n        case when instr(content_text, \' \', 1) = 0 and instr(content_text, \'-\', 1) = 0 then content_text\n        when instr(content_text, \' \', 1) <> 0 and instr(content_text, \'-\', 1) <> 0 and instr(content_text, \' \', 1) < instr(content_text, \'-\', 1) then SUBSTR(content_text, 1, INSTR(content_text, \' \') - 1)\n        when instr(content_text, \' \', 1) <> 0 and instr(content_text, \'-\', 1) <> 0 and instr(content_text, \'-\', 1) < instr(content_text, \' \', 1) then SUBSTR(content_text, 1, INSTR(content_text, \'-\') - 1)\n        when instr(content_text, \' \', 1) <> 0 and instr(content_text, \'-\', 1) = 0 then SUBSTR(content_text, 1, INSTR(content_text, \' \') - 1)\n        when instr(content_text, \' \', 1) = 0 and instr(content_text, \'-\', 1) <> 0 then SUBSTR(content_text, 1, INSTR(content_text, \'-\') - 1)\n        end AS word,\n        case when instr(content_text, \' \', 1) = 0 and instr(content_text, \'-\', 1) = 0 then \'\'\n        when instr(content_text, \' \', 1) <> 0 and instr(content_text, \'-\', 1) <> 0 and instr(content_text, \' \', 1) < instr(content_text, \'-\', 1) then SUBSTR(content_text, INSTR(content_text, \' \'), 1000)\n        when instr(content_text, \' \', 1) <> 0 and instr(content_text, \'-\', 1) <> 0 and instr(content_text, \'-\', 1) < instr(content_text, \' \', 1) then SUBSTR(content_text, INSTR(content_text, \'-\'), 1000)\n        when instr(content_text, \' \', 1) <> 0 and instr(content_text, \'-\', 1) = 0 then SUBSTR(content_text, INSTR(content_text, \' \'), 1000)\n        when instr(content_text, \' \', 1) = 0 and instr(content_text, \'-\', 1) <> 0 then SUBSTR(content_text, INSTR(content_text, \'-\'), 1000)\n        end AS remaining,\n        1 AS word_level\n        from user_content\n    UNION ALL\n    SELECT \n        content_sep_words.content_id,\n        content_sep_words.content_text,\n        substr(remaining, 1, 1) as delim,\n        case when instr(substr(remaining, 2, 1000), \' \', 1) = 0 and instr(substr(remaining, 2, 1000), \'-\', 1) = 0 then substr(remaining, 2, 1000)\n        when instr(substr(remaining, 2, 1000), \' \', 1) <> 0 and instr(substr(remaining, 2, 1000), \'-\', 1) <> 0 and instr(substr(remaining, 2, 1000), \' \', 1) < instr(substr(remaining, 2, 1000), \'-\', 1) then SUBSTR(substr(remaining, 2, 1000), 1, INSTR(substr(remaining, 2, 1000), \' \') - 1)\n        when instr(substr(remaining, 2, 1000), \' \', 1) <> 0 and instr(substr(remaining, 2, 1000), \'-\', 1) <> 0 and instr(substr(remaining, 2, 1000), \'-\', 1) < instr(substr(remaining, 2, 1000), \' \', 1) then SUBSTR(substr(remaining, 2, 1000), 1, INSTR(substr(remaining, 2, 1000), \'-\') - 1)\n        when instr(substr(remaining, 2, 1000), \' \', 1) <> 0 and instr(substr(remaining, 2, 1000), \'-\', 1) = 0 then SUBSTR(substr(remaining, 2, 1000), 1, INSTR(substr(remaining, 2, 1000), \' \') - 1)\n        when instr(substr(remaining, 2, 1000), \' \', 1) = 0 and instr(substr(remaining, 2, 1000), \'-\', 1) <> 0 then SUBSTR(substr(remaining, 2, 1000), 1, INSTR(substr(remaining, 2, 1000), \'-\') - 1)\n        end AS word,\n        case when instr(substr(remaining, 2, 1000), \' \', 1) = 0 and instr(substr(remaining, 2, 1000), \'-\', 1) = 0 then \'\'\n        when instr(substr(remaining, 2, 1000), \' \', 1) <> 0 and instr(substr(remaining, 2, 1000), \'-\', 1) <> 0 and instr(substr(remaining, 2, 1000), \' \', 1) < instr(substr(remaining, 2, 1000), \'-\', 1) then SUBSTR(substr(remaining, 2, 1000), INSTR(substr(remaining, 2, 1000), \' \'), 1000)\n        when instr(substr(remaining, 2, 1000), \' \', 1) <> 0 and instr(substr(remaining, 2, 1000), \'-\', 1) <> 0 and instr(substr(remaining, 2, 1000), \'-\', 1) < instr(substr(remaining, 2, 1000), \' \', 1) then SUBSTR(substr(remaining, 2, 1000), INSTR(substr(remaining, 2, 1000), \'-\'), 1000)\n        when instr(substr(remaining, 2, 1000), \' \', 1) <> 0 and instr(substr(remaining, 2, 1000), \'-\', 1) = 0 then SUBSTR(substr(remaining, 2, 1000), INSTR(substr(remaining, 2, 1000), \' \'), 1000)\n        when instr(substr(remaining, 2, 1000), \' \', 1) = 0 and instr(substr(remaining, 2, 1000), \'-\', 1) <> 0 then SUBSTR(substr(remaining, 2, 1000), INSTR(substr(remaining, 2, 1000), \'-\'), 1000)\n        end AS remaining,\n        word_level + 1\n    FROM content_sep_words\n    WHERE REMAINING is not null\n),\ncontent_sep_words_capitalized as (\n    select content_id,\n    content_text,\n    word_level as word_seq,\n    word,\n    nvl(delim, \'\')||upper(substr(WORD, 1, 1))||lower(substr(WORD, 2, 1000)) as formatted_word\n    from content_sep_words\n)\nselect\ncontent_id,\ncontent_text as original_text,\nLISTAGG(formatted_word, \'\') WITHIN GROUP (ORDER BY word_seq) as converted_text\nfrom content_sep_words_capitalized\ngroup by content_id, content_text\norder by 1\n```\n``` MySQL []\n# Write your MySQL query statement below\n\nWITH recursive content_sep_words AS (\n    SELECT\n        content_id,\n        content_text,\n        \' \' as delim,\n        case when instr(content_text, \' \') = 0 and instr(content_text, \'-\') = 0 then content_text\n        when instr(content_text, \' \') <> 0 and instr(content_text, \'-\') <> 0 and instr(content_text, \' \') < instr(content_text, \'-\') then substring(content_text, 1, INSTR(content_text, \' \') - 1)\n        when instr(content_text, \' \') <> 0 and instr(content_text, \'-\') <> 0 and instr(content_text, \'-\') < instr(content_text, \' \') then substring(content_text, 1, INSTR(content_text, \'-\') - 1)\n        when instr(content_text, \' \') <> 0 and instr(content_text, \'-\') = 0 then substring(content_text, 1, INSTR(content_text, \' \') - 1)\n        when instr(content_text, \' \') = 0 and instr(content_text, \'-\') <> 0 then substring(content_text, 1, INSTR(content_text, \'-\') - 1)\n        end AS word,\n        case when instr(content_text, \' \') = 0 and instr(content_text, \'-\') = 0 then \'\'\n        when instr(content_text, \' \') <> 0 and instr(content_text, \'-\') <> 0 and instr(content_text, \' \') < instr(content_text, \'-\') then substring(content_text, INSTR(content_text, \' \'), 1000)\n        when instr(content_text, \' \') <> 0 and instr(content_text, \'-\') <> 0 and instr(content_text, \'-\') < instr(content_text, \' \') then substring(content_text, INSTR(content_text, \'-\'), 1000)\n        when instr(content_text, \' \') <> 0 and instr(content_text, \'-\') = 0 then substring(content_text, INSTR(content_text, \' \'), 1000)\n        when instr(content_text, \' \') = 0 and instr(content_text, \'-\') <> 0 then substring(content_text, INSTR(content_text, \'-\'), 1000)\n        end AS remaining,\n        1 AS word_level\n        from user_content\n    UNION ALL\n    SELECT \n        content_sep_words.content_id,\n        content_sep_words.content_text,\n        substr(remaining, 1, 1) as delim,\n        case when instr(substring(remaining, 2, 1000), \' \') = 0 and instr(substring(remaining, 2, 1000), \'-\') = 0 then substring(remaining, 2, 1000)\n        when instr(substring(remaining, 2, 1000), \' \') <> 0 and instr(substring(remaining, 2, 1000), \'-\') <> 0 and instr(substring(remaining, 2, 1000), \' \') < instr(substring(remaining, 2, 1000), \'-\') then substring(substring(remaining, 2, 1000), 1, INSTR(substring(remaining, 2, 1000), \' \') - 1)\n        when instr(substring(remaining, 2, 1000), \' \') <> 0 and instr(substring(remaining, 2, 1000), \'-\') <> 0 and instr(substring(remaining, 2, 1000), \'-\') < instr(substring(remaining, 2, 1000), \' \') then substring(substring(remaining, 2, 1000), 1, INSTR(substring(remaining, 2, 1000), \'-\') - 1)\n        when instr(substring(remaining, 2, 1000), \' \') <> 0 and instr(substring(remaining, 2, 1000), \'-\') = 0 then substring(substring(remaining, 2, 1000), 1, INSTR(substring(remaining, 2, 1000), \' \') - 1)\n        when instr(substring(remaining, 2, 1000), \' \') = 0 and instr(substring(remaining, 2, 1000), \'-\') <> 0 then substring(substring(remaining, 2, 1000), 1, INSTR(substring(remaining, 2, 1000), \'-\') - 1)\n        end AS word,\n        case when instr(substring(remaining, 2, 1000), \' \') = 0 and instr(substring(remaining, 2, 1000), \'-\') = 0 then \'\'\n        when instr(substring(remaining, 2, 1000), \' \') <> 0 and instr(substring(remaining, 2, 1000), \'-\') <> 0 and instr(substring(remaining, 2, 1000), \' \') < instr(substring(remaining, 2, 1000), \'-\') then substring(substring(remaining, 2, 1000), INSTR(substring(remaining, 2, 1000), \' \'), 1000)\n        when instr(substring(remaining, 2, 1000), \' \') <> 0 and instr(substring(remaining, 2, 1000), \'-\') <> 0 and instr(substring(remaining, 2, 1000), \'-\') < instr(substring(remaining, 2, 1000), \' \') then substring(substring(remaining, 2, 1000), INSTR(substring(remaining, 2, 1000), \'-\'), 1000)\n        when instr(substring(remaining, 2, 1000), \' \') <> 0 and instr(substring(remaining, 2, 1000), \'-\') = 0 then substring(substring(remaining, 2, 1000), INSTR(substring(remaining, 2, 1000), \' \'), 1000)\n        when instr(substring(remaining, 2, 1000), \' \') = 0 and instr(substring(remaining, 2, 1000), \'-\') <> 0 then substring(substring(remaining, 2, 1000), INSTR(substring(remaining, 2, 1000), \'-\'), 1000)\n        end AS remaining,\n        word_level + 1\n    FROM content_sep_words\n    WHERE remaining <> \'\'\n),\ncontent_sep_words_capitalized as (\n    select content_id,\n    content_text,\n    word_level as word_seq,\n    word,\n    CONCAT(coalesce(delim, \'\'), upper(substring(WORD, 1, 1)), lower(substring(WORD, 2, 1000))) as formatted_word\n    from content_sep_words\n)\nselect\ncontent_id,\ncontent_text as original_text,\nsubstr(group_concat(formatted_word order by word_seq separator \'\'), 2, 1000) as converted_text\nfrom content_sep_words_capitalized\ngroup by 1, 2\norder by 1\n```\n``` MSSQL []\n/* Write your T-SQL query statement below */\n\nWITH content_sep_words AS (\n    SELECT\n        content_id,\n        content_text,\n        \'\' as delim,\n        case when CHARINDEX(\' \', content_text) = 0 and CHARINDEX(\'-\', content_text) = 0 then content_text\n        when CHARINDEX(\' \', content_text) <> 0 and CHARINDEX(\'-\', content_text) <> 0 and CHARINDEX(\' \', content_text) < CHARINDEX(\'-\', content_text) then substring(content_text, 1, CHARINDEX(\' \', content_text) - 1)\n        when CHARINDEX(\' \', content_text) <> 0 and CHARINDEX(\'-\', content_text) <> 0 and CHARINDEX(\'-\', content_text) < CHARINDEX(\' \', content_text) then substring(content_text, 1, CHARINDEX(\'-\', content_text) - 1)\n        when CHARINDEX(\' \', content_text) <> 0 and CHARINDEX(\'-\', content_text) = 0 then substring(content_text, 1, CHARINDEX(\' \', content_text) - 1)\n        when CHARINDEX(\' \', content_text) = 0 and CHARINDEX(\'-\', content_text) <> 0 then substring(content_text, 1, CHARINDEX(\'-\', content_text) - 1)\n        end AS word,\n        case when CHARINDEX(\' \', content_text) = 0 and CHARINDEX(\'-\', content_text) = 0 then \'\'\n        when CHARINDEX(\' \', content_text) <> 0 and CHARINDEX(\'-\', content_text) <> 0 and CHARINDEX(\' \', content_text) < CHARINDEX(\'-\', content_text) then substring(content_text, CHARINDEX(\' \', content_text), 1000)\n        when CHARINDEX(\' \', content_text) <> 0 and CHARINDEX(\'-\', content_text) <> 0 and CHARINDEX(\'-\', content_text) < CHARINDEX(\' \', content_text) then substring(content_text, CHARINDEX(\'-\', content_text), 1000)\n        when CHARINDEX(\' \', content_text) <> 0 and CHARINDEX(\'-\', content_text) = 0 then substring(content_text, CHARINDEX(\' \', content_text), 1000)\n        when CHARINDEX(\' \', content_text) = 0 and CHARINDEX(\'-\', content_text) <> 0 then substring(content_text, CHARINDEX(\'-\', content_text), 1000)\n        end AS remaining,\n        1 AS word_level\n        from user_content\n    UNION ALL\n    SELECT \n        content_sep_words.content_id,\n        content_sep_words.content_text,\n        substring(remaining, 1, 1) as delim,\n        case when CHARINDEX(\' \', substring(remaining, 2, 1000)) = 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) = 0 then substring(remaining, 2, 1000)\n        when CHARINDEX(\' \', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\' \', substring(remaining, 2, 1000)) < CHARINDEX(\'-\', substring(remaining, 2, 1000)) then substring(substring(remaining, 2, 1000), 1, CHARINDEX(\' \', substring(remaining, 2, 1000)) - 1)\n        when CHARINDEX(\' \', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) < CHARINDEX(\' \', substring(remaining, 2, 1000)) then substring(substring(remaining, 2, 1000), 1, CHARINDEX(\'-\', substring(remaining, 2, 1000)) - 1)\n        when CHARINDEX(\' \', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) = 0 then substring(substring(remaining, 2, 1000), 1, CHARINDEX(\' \', substring(remaining, 2, 1000)) - 1)\n        when CHARINDEX(\' \', substring(remaining, 2, 1000)) = 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) <> 0 then substring(substring(remaining, 2, 1000), 1, CHARINDEX(\'-\', substring(remaining, 2, 1000)) - 1)\n        end AS word,\n        case when CHARINDEX(\' \', substring(remaining, 2, 1000)) = 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) = 0 then \'\'\n        when CHARINDEX(\' \', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\' \', substring(remaining, 2, 1000)) < CHARINDEX(\'-\', substring(remaining, 2, 1000)) then substring(substring(remaining, 2, 1000), CHARINDEX(\' \', substring(remaining, 2, 1000)), 1000)\n        when CHARINDEX(\' \', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) < CHARINDEX(\' \', substring(remaining, 2, 1000)) then substring(substring(remaining, 2, 1000), CHARINDEX(\'-\', substring(remaining, 2, 1000)), 1000)\n        when CHARINDEX(\' \', substring(remaining, 2, 1000)) <> 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) = 0 then substring(substring(remaining, 2, 1000), CHARINDEX(\' \', substring(remaining, 2, 1000)), 1000)\n        when CHARINDEX(\' \', substring(remaining, 2, 1000)) = 0 and CHARINDEX(\'-\', substring(remaining, 2, 1000)) <> 0 then substring(substring(remaining, 2, 1000), CHARINDEX(\'-\', substring(remaining, 2, 1000)), 1000)\n        end AS remaining,\n        word_level + 1\n    FROM content_sep_words\n    WHERE remaining <> \'\'\n),\ncontent_sep_words_capitalized as (\n    select content_id,\n    content_text,\n    word_level as word_seq,\n    word,\n    CONCAT(coalesce(delim, \'\'), upper(substring(WORD, 1, 1)), lower(substring(WORD, 2, 1000))) as formatted_word\n    from content_sep_words\n)\nselect\ncontent_id,\ncontent_text as original_text,\nSTRING_AGG(formatted_word, \'\') within group (order by word_seq) as converted_text\nfrom content_sep_words_capitalized\ngroup by content_id, content_text\norder by 1\n```\n``` Postgres []\n-- Write your PostgreSQL query statement below\n\nWITH RECURSIVE content_sep_words AS (\n    SELECT\n        content_id,\n        content_text,\n        \'\' as delim,\n        case when POSITION(\' \' IN content_text) = 0 and POSITION(\'-\' IN content_text) = 0 then content_text\n        when POSITION(\' \' IN content_text) <> 0 and POSITION(\'-\' IN content_text) <> 0 and POSITION(\' \' IN content_text) < POSITION(\'-\' IN content_text) then substring(content_text, 1, POSITION(\' \' IN content_text) - 1)\n        when POSITION(\' \' IN content_text) <> 0 and POSITION(\'-\' IN content_text) <> 0 and POSITION(\'-\' IN content_text) < POSITION(\' \' IN content_text) then substring(content_text, 1, POSITION(\'-\' IN content_text) - 1)\n        when POSITION(\' \' IN content_text) <> 0 and POSITION(\'-\' IN content_text) = 0 then substring(content_text, 1, POSITION(\' \' IN content_text) - 1)\n        when POSITION(\' \' IN content_text) = 0 and POSITION(\'-\' IN content_text) <> 0 then substring(content_text, 1, POSITION(\'-\' IN content_text) - 1)\n        end AS word,\n        case when POSITION(\' \' IN content_text) = 0 and POSITION(\'-\' IN content_text) = 0 then \'\'\n        when POSITION(\' \' IN content_text) <> 0 and POSITION(\'-\' IN content_text) <> 0 and POSITION(\' \' IN content_text) < POSITION(\'-\' IN content_text) then substring(content_text, POSITION(\' \' IN content_text), 1000)\n        when POSITION(\' \' IN content_text) <> 0 and POSITION(\'-\' IN content_text) <> 0 and POSITION(\'-\' IN content_text) < POSITION(\' \' IN content_text) then substring(content_text, POSITION(\'-\' IN content_text), 1000)\n        when POSITION(\' \' IN content_text) <> 0 and POSITION(\'-\' IN content_text) = 0 then substring(content_text, POSITION(\' \' IN content_text), 1000)\n        when POSITION(\' \' IN content_text) = 0 and POSITION(\'-\' IN content_text) <> 0 then substring(content_text, POSITION(\'-\' IN content_text), 1000)\n        end AS remaining,\n        1 AS word_level\n        from user_content\n    UNION ALL\n    SELECT \n        content_sep_words.content_id,\n        content_sep_words.content_text,\n        substr(remaining, 1, 1) as delim,\n        case when POSITION(\' \' IN substring(remaining, 2, 1000)) = 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) = 0 then substring(remaining, 2, 1000)\n        when POSITION(\' \' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\' \' IN substring(remaining, 2, 1000)) < POSITION(\'-\' IN substring(remaining, 2, 1000)) then substring(substring(remaining, 2, 1000), 1, POSITION(\' \' IN substring(remaining, 2, 1000)) - 1)\n        when POSITION(\' \' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) < POSITION(\' \' IN substring(remaining, 2, 1000)) then substring(substring(remaining, 2, 1000), 1, POSITION(\'-\' IN substring(remaining, 2, 1000)) - 1)\n        when POSITION(\' \' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) = 0 then substring(substring(remaining, 2, 1000), 1, POSITION(\' \' IN substring(remaining, 2, 1000)) - 1)\n        when POSITION(\' \' IN substring(remaining, 2, 1000)) = 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) <> 0 then substring(substring(remaining, 2, 1000), 1, POSITION(\'-\' IN substring(remaining, 2, 1000)) - 1)\n        end AS word,\n        case when POSITION(\' \' IN substring(remaining, 2, 1000)) = 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) = 0 then \'\'\n        when POSITION(\' \' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\' \' IN substring(remaining, 2, 1000)) < POSITION(\'-\' IN substring(remaining, 2, 1000)) then substring(substring(remaining, 2, 1000), POSITION(\' \' IN substring(remaining, 2, 1000)), 1000)\n        when POSITION(\' \' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) < POSITION(\' \' IN substring(remaining, 2, 1000)) then substring(substring(remaining, 2, 1000), POSITION(\'-\' IN substring(remaining, 2, 1000)), 1000)\n        when POSITION(\' \' IN substring(remaining, 2, 1000)) <> 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) = 0 then substring(substring(remaining, 2, 1000), POSITION(\' \' IN substring(remaining, 2, 1000)), 1000)\n        when POSITION(\' \' IN substring(remaining, 2, 1000)) = 0 and POSITION(\'-\' IN substring(remaining, 2, 1000)) <> 0 then substring(substring(remaining, 2, 1000), POSITION(\'-\' IN substring(remaining, 2, 1000)), 1000)\n        end AS remaining,\n        word_level + 1\n    FROM content_sep_words\n    WHERE remaining <> \'\'\n),\ncontent_sep_words_capitalized as (\n    select content_id,\n    content_text,\n    word_level as word_seq,\n    word,\n    CONCAT(coalesce(delim, \'\'), upper(substring(WORD, 1, 1)), lower(substring(WORD, 2, 1000))) as formatted_word\n    from content_sep_words\n)\nselect\ncontent_id,\ncontent_text as original_text,\nSTRING_AGG(formatted_word, \'\' order by word_seq) as converted_text\nfrom content_sep_words_capitalized\ngroup by 1, 2\norder by 1\n```
['MySQL', 'Oracle', 'MS SQL Server', 'PostgreSQL']