Home » SQL & PL/SQL » SQL & PL/SQL » SQL to transform a single row into multiple rows. (Oracle 11g)
SQL to transform a single row into multiple rows. [message #580335] Fri, 22 March 2013 21:35 Go to next message
saella
Messages: 1
Registered: May 2011
Junior Member
Hi, I need some help in writing the sql, to transform a single row into multiple rows. I am trying to create multiple rows based on a value of a column in the table.In the below example, I am trying to create the rows based on the 'Col2' values. Please find the below example:

Original table data:

Col1 Col2 Col3 Col4

Row1 a1 a,b,c 01 ON
Row2 b1 d,e,f 02 OFF
Row3 c1 g,h 03 ON


I want the above table to be transformed into below:

Col1 Col2 Col3 Col4

Row1 a1 a 01 ON
Row1 a1 b 01 ON
Row1 a1 C 01 ON
Row2 b1 d 02 OFF
Row2 b1 e 02 OFF
Row2 b1 f 02 OFF
Row3 c1 g 03 ON
Row3 c1 h 03 ON

Thanks in advance.
Re: SQL to transform a single row into multiple rows. [message #580336 is a reply to message #580335] Fri, 22 March 2013 21:49 Go to previous messageGo to next message
BlackSwan
Messages: 22718
Registered: January 2009
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/

It violates Third Normal Form to store more than 1 value in a single column; like "a,b,c".
Re: SQL to transform a single row into multiple rows. [message #580340 is a reply to message #580335] Sat, 23 March 2013 01:39 Go to previous message
Michel Cadot
Messages: 58938
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Welcome to the forum.

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" or "Preview Quick Reply" button to verify.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Read this post and the two subsequent ones.

Regards
Michel
Previous Topic: removed special characters
Next Topic: Query Error
Goto Forum:
  


Current Time: Fri Aug 29 13:28:29 CDT 2014

Total time taken to generate the page: 0.09099 seconds