SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to write Transpose in Oracle Please Help


How to write Transpose in Oracle Please Help

Author
Message
vp7986
vp7986
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 16
sample date
-----------
source
------
ID-----NAME-----------ADD1--------ADD2---------ADD3------ADD4-------ADD5---------ADD6

1 ------ ABC 12B 13B 14B 15B 16B 17B
2 ------ BBC 10V VCF BB
3------ ADD 30

TARGET
-----
id ------ NAME------ADD
1-------ABC--------12B
1-------ABC--------10V
1-------ABC--------13B
1-------ABC--------14B
1-------ABC--------15B
1-------ABC--------16B
1-------ABC--------17B
2-------BBC--------10V
2-------BBC--------VCF
2-------BBC--------BB
3-------ADD--------30
Sean Lange
Sean Lange
SSC Guru
SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)SSC Guru (58K reputation)

Group: General Forum Members
Points: 58977 Visits: 17943
You are not too likely to find a lot of Oracle people around here since this is sql server forum. Even if you do, they will ask you for the same thing. ddl (create table), sample data (insert statements) and desired output based on your sample data. From what you posted i am not exactly sure what you have as tables and what you want as output. And of course in Oracle I am useless. :-)

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Lowell
Lowell
SSC Guru
SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)SSC Guru (67K reputation)

Group: General Forum Members
Points: 67389 Visits: 40891
if you google "Oracle UNPIVOT", you should get some examples of this "transpose" thing you are looking for.

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Gianluca Sartori
Gianluca Sartori
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22609 Visits: 13361

WITH source(ID, NAME, ADD1, ADD2, ADD3, ADD4, ADD5, ADD6) AS (
SELECT 1, 'ABC', '12B', '13B', '14B', '15B', '16B', '17B' FROM dual
UNION ALL
SELECT 2, 'BBC', '10V', 'VCF', 'BB', NULL, NULL, NULL FROM dual
UNION ALL
SELECT 3, 'ADD', '30', NULL, NULL, NULL, NULL, NULL FROM dual
)
SELECT ID, NAME, "ADD"
FROM source
UNPIVOT ( "ADD" FOR col IN (ADD1, ADD2, ADD3, ADD4, ADD5, ADD6));



Tested on oracle 11.2.0.1.

--Gianluca Sartori

How to post T-SQL questions
spaghettidba.com
@spaghettidba
Phil Parkin
Phil Parkin
SSC-Forever
SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)SSC-Forever (48K reputation)

Group: General Forum Members
Points: 48533 Visits: 21123
Gianluca Sartori (8/30/2012)

--snip
Tested on oracle 11.2.0.1.


Turncoat!
:-)


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Gianluca Sartori
Gianluca Sartori
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22609 Visits: 13361
:-)
Sins of a past life boiling to the surface...

--Gianluca Sartori

How to post T-SQL questions
spaghettidba.com
@spaghettidba
vp7986
vp7986
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 16
Thanks this example works perfectly...But This is an example i have provided but in real life we have table and columns names.

Can you give me this as columns names with out selecting data.
Gianluca Sartori
Gianluca Sartori
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22609 Visits: 13361
vp7986 (8/30/2012)
Thanks this example works perfectly...But This is an example i have provided but in real life we have table and columns names.

Can you give me this as columns names with out selecting data.


Sorry, but I can't believe you can't do it yourself.

--Gianluca Sartori

How to post T-SQL questions
spaghettidba.com
@spaghettidba
Gianluca Sartori
Gianluca Sartori
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22609 Visits: 13361
Also, you didn't provide any table name. Is "source" the name of your table?

--Gianluca Sartori

How to post T-SQL questions
spaghettidba.com
@spaghettidba
vp7986
vp7986
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 Visits: 16
I am only Concerned on this

SELECT 1, 'ABC', '12B', '13B', '14B', '15B', '16B', '17B' FROM dual
UNION ALL
SELECT 2, 'BBC', '10V', 'VCF', 'BB', NULL, NULL, NULL FROM dual
UNION ALL
SELECT 3, 'ADD', '30', NULL, NULL, NULL, NULL, NULL FROM dual
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search