Home » SQL & PL/SQL » SQL & PL/SQL » select statement to split string as per the content and show it (oracle 11g, windows)
select statement to split string as per the content and show it [message #655479] Wed, 31 August 2016 14:19 Go to next message
chinmay89
Messages: 11
Registered: August 2016
Junior Member
Hi All,

Hope you are doing well.

Please find the requirement.

Create table statement
 
create table ABC_MASTER (Part_number varchar(40),Filename varchar(80));

Insert table statement
insert into ABC_MASTER values (123, abc*cvbsmdm*cbdjdk(9)*asdre-01);
insert into ABC_MASTER values (124, qwe);

Now the task is the select statement from ABC_MASTER which shows like this, split the string as per (*)

part_number................filename
123............................abc
123............................cvbsmdm
123............................cbdjdk(9)
123............................asdre-01
124............................qwe

Thanks
Chinmay



Re: select statement to split string as per the content and show it [message #655483 is a reply to message #655479] Wed, 31 August 2016 15:04 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

SQL> select part_number, regexp_substr(filename,'[^*]+',1,column_value) filename
  2  from ABC_MASTER,
  3       table(cast(multiset(select level from dual
  4                           connect by level <= regexp_count(filename,'\*')+1)
  5                  as sys.odciNumberList))
  6  order by 1, column_value
  7  /

PART_NUMBER                              FILENAME
---------------------------------------- ---------------
123                                      abc
123                                      cvbsmdm
123                                      cbdjdk(9)
123                                      asdre-01
124                                      qwe
Re: select statement to split string as per the content and show it [message #655486 is a reply to message #655483] Wed, 31 August 2016 15:08 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
only an amateur or fool stores more than 1 value in a single column.

the data should be Normalized.
Re: select statement to split string as per the content and show it [message #655528 is a reply to message #655483] Thu, 01 September 2016 04:11 Go to previous messageGo to next message
chinmay89
Messages: 11
Registered: August 2016
Junior Member
This is not working for me Sad

@Blackswan

I have an Excel sheet and i am inserting everything in the excel sheet in the database tables(using ETL tool)

/forum/fa/13250/0/

and the table output inserts it in a single line.

Its not about storing more than 1 value in a single column.

Thats why i am filtering it out as per the requirement.

Re: select statement to split string as per the content and show it [message #655529 is a reply to message #655528] Thu, 01 September 2016 04:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

chinmay89 wrote on Thu, 01 September 2016 11:11
This is not working for me Sad
which does not tell us anything about what you did and what could be the problem.
Don't you how I have posted? Do it in the same way.

Please read How to use [code] tags and make your code easier to read.

[Updated on: Thu, 01 September 2016 04:14]

Report message to a moderator

Re: select statement to split string as per the content and show it [message #655593 is a reply to message #655528] Mon, 05 September 2016 04:20 Go to previous message
sandeep_orafaq
Messages: 88
Registered: September 2014
Member
First of all your insert statements are not rightly formatted.

So far as I understand you are not doing the conversion of excel column to desired result set in ETL tool, but you are trying to achieve this in Database post ETL.
If so, then explain why Michel's solution is not working for you?
Previous Topic: Hierarchy view
Next Topic: Unpivot or Connect by
Goto Forum:
  


Current Time: Fri Apr 26 10:27:07 CDT 2024