Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Split one row from dual into several different columns

How to use regular expressions in such a case?

select 'John Doe   jr.' from dual;

As a result, I would like to see it like this:

col 1 col2 col3
John Doe jr.

There is a line that contains spaces, you need to remove all spaces from the line and split it into columns.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I use Oracle 19c

>Solution :

With sample data you posted, this is one option – return the 1st, 2nd and 3rd word (followed by a dot):

SQL> with test (col) as
  2    (select 'John Doe   jr.' from dual)
  3  select regexp_substr(col, '\w+', 1, 1) col1,
  4         regexp_substr(col, '\w+', 1, 2) col2,
  5         regexp_substr(col, '\w+.', 1, 3) col3
  6  from test;

COL1 COL COL
---- --- ---
John Doe jr.

SQL>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading