split the column values in multiple column

Hello Experts:

I have following column value

/test1/folder/file__000000000__text.txt

I want to take the filename "file__000000000__text.txt"

and add in multiple columns like this

columnA      ColumnB        ColumnC
file                 000000000     text.txt
LVL 5
CalmSoulAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Farzad AkbarnejadDeveloperCommented:
Hi,
suppose col of testqaq table contains   /test1/folder/file__000000000__text.txt
Try this:

select substr(substr(col, instr(col,'/',-1)+1), 1,4) as columnA,
           substr(substr(col, instr(col,'/',-1)+1), 7,9) as columnB,
        substr(substr(col, instr(col,'/',-1)+1), 18) as columnC,
  q.* from testqa q;

-FA
slightwv (䄆 Netminder) Commented:
I assume the number of characters can change in the string.

Try this:
select
	regexp_substr(col,'[a-z]+',instr(col,'/',-1),1) colA,
	regexp_substr(col,'[0-9]+',instr(col,'/',-1),1) colB,
	regexp_substr(col,'[a-z.]+$') colC
from mydata
/

Open in new window

CalmSoulAuthor Commented:
I don't want to select he column add data to new columns I.e split value in multiple columns a to c
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

slightwv (䄆 Netminder) Commented:
>>I don't want to select he column add data to new columns I.e split value in multiple columns a to c

I don't understand what this means.

The queries above seem to provide your expected results.

If you want to put those values into a table, just add an insert or update to it.

update table set (colA,colB,colC) = (select regexp_substr(col,'[a-z]+',instr(col,'/',-1),1) colA,
      regexp_substr(col,'[0-9]+',instr(col,'/',-1),1) colB,
      regexp_substr(col,'[a-z.]+$') colC
from mydata
) where ...

If you can add more information to your question, we can provide more exact SQL.
awking00Information Technology SpecialistCommented:
>>I don't want to select he column add data to new columns I.e split value in multiple columns a to c<<
Are you talking about adding three new columns to your existing table?
slightwv (䄆 Netminder) Commented:
>>Are you talking about adding three new columns to your existing table?

If that is what you are after, I would look at using Virtual Columns with the regular expressions above.

Here is an example using Virtual Columns:
drop table tab1 purge;
create table tab1(
col varchar2(100),
colA varchar2(100) generated always as (regexp_substr(col,'[a-z]+',instr(col,'/',-1),1)),
colB varchar2(100) generated always as (regexp_substr(col,'[0-9]+',instr(col,'/',-1),1)),
colC varchar2(100) generated always as (regexp_substr(col,'[a-z.]+$'))
);


insert into tab1(col) values('/test1/folder/file__000000000__text.txt');
commit;

select * from tab1;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.