0

I have data stored as text within a MySQL database that has values separated by newlines which I need to split into rows. A single text field might look like this:

---
'2022-06-19': no_capacity
'2022-06-20': no_capacity
'2022-06-21': available
'2022-06-22': available
...

Yes this is an example of a single text field. There can be anywhere between 100-500 \n's. The dates themselves are also unpredictable.

I need each one of these 'rows' within the entry to be returned as an actual row in a table (and then columns split on the colon, but that is less important).Can this be done using a MySQL query?

Hunter Boyd
  • 165
  • 10
  • This type of question has been asked many times on Stack Overflow. I voted to close this as a duplicate, so I had to pick one with a well-written answer. But a search finds over 200 other matches: https://stackoverflow.com/search?q=%5Bmysql%5D+split+string+into+rows – Bill Karwin Oct 11 '22 at 16:56

1 Answers1

1

You should be able to use something similar to this answer but for a newline character. This can't be done using a regular Mysql query, but rather a stored procedure similar to the answers in that post, which I'm not familiar with. Not sure if this helps, other answers might be necessary.