A couple things:
- This sounds like a version of the common question "how do I split a comma-separated string", but with CRLF instead of commas. The answers on that link are great, so be sure to look at those.
- You aren't really clear about whether your separator is the string "CRLF" or an actual carriage return-line feed combination. I'm going to guess it's the second one, which in Oracle can be represented as
chr(13)||chr(10)
- The simple answer (below) will only really work for a single input row. If you want this to work on multiple rows, you'll have to tell us what primary key you're using for this table (e.g.
id
). Again, see the link above for a great example of a really clear question.
Anyway, here's the usual way of splitting a newline-delimited string into ROWS. This is what most people do. The regexp is the only part I changed here for your situation (CRLF instead of comma).
-- sample data
with table_1 as (select 'John Doe' || chr(13)||chr(10) || '555-555-5555' || chr(13)||chr(10) || 'This is a test message' as message from dual)
-- query
select regexp_substr(message, '^[^'||chr(13)||']+', 1, level,'m')
from table_1
connect by regexp_substr(message, '^[^'||chr(13)||']+', 1, level,'m') is not null;
If you want to split it into COLUMNS, I don't think there's an easy way of generating a dynamic number of columns, so you'll have to manually set up each column.
-- sample data
with table_1 as (select 'John Doe' || chr(13)||chr(10) || '555-555-5555' || chr(13)||chr(10) || 'This is a test message' as message from dual)
-- query
select regexp_substr(message, '^[^'||chr(13)||']+', 1, 1,'m') as col1,
regexp_substr(message, '^[^'||chr(13)||']+', 1, 2,'m') as col2,
regexp_substr(message, '^[^'||chr(13)||']+', 1, 3,'m') as col3
from table_1
;