Home » SQL & PL/SQL » SQL & PL/SQL » COLUMN TO ROW & ROW TO COLUMN (Oracle 10G ,Window XP)
| COLUMN TO ROW & ROW TO COLUMN [message #563925] |
Sat, 18 August 2012 03:44  |
|
|
Hi All,
Please find attached document. It has data extracted from query.
In that i need to convert some columns data to row and all rows to column.
Columns to row:
SALES
OTHER_OUTFLOWS
DISBURSEMENTS
MVA_OUTFLOWS
Row To Column
FACT_TRANSACTION
FACT_TRANSACTION_DETAIL
FACT_FLOW_AGGREGATE
Attachment: DATA.jpg
SELECT jobname, last_run_date, channel, sub_channel, pcode, SALES,
other_outflows, disbursements, mva_outflows
FROM TBL_BI_JOBS WHERE last_run_date='20-JAN-2005'
Please help me on this.
Thanks
Viswanathan.S
-
Attachment: DATA.jpg
(Size: 112.16KB, Downloaded 27 times)
|
|
|
|
|
|
|
|
| Re: COLUMN TO ROW & ROW TO COLUMN [message #563929 is a reply to message #563928] |
Sat, 18 August 2012 05:45   |
 |
Michel Cadot
Messages: 54672 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
I cannot execute an excel file in SQL*Plus.
Is there anything you don't understand in the following sentence; if so then tell us I will clear it:
Quote:Post a working Test case: create table 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.
Regards
Michel
[Updated on: Sat, 18 August 2012 05:46] Report message to a moderator
|
|
|
|
| Re: COLUMN TO ROW & ROW TO COLUMN [message #563930 is a reply to message #563925] |
Sat, 18 August 2012 06:19   |
|
|
Hi ,
Table TBL_BI_JOBS got loaded from different 3 scripts(Cursor statments).
We have to change the row to column and column to row in table TBL_BI_JOBS.
Normal result query:
SELECT jobname, last_run_date, channel, sub_channel, pcode, SALES,
other_outflows, disbursements, mva_outflows
FROM TBL_BI_JOBS WHERE last_run_date='20-JAN-2005'
we have to modify this query for data should be as like in excel sheet.
Thanks
Viswanathan.S
|
|
|
|
| Re: COLUMN TO ROW & ROW TO COLUMN [message #563931 is a reply to message #563930] |
Sat, 18 August 2012 07:37   |
John Watson
Messages: 3174 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
OK, I'll have try.
You need to provide the statements that will create the table and insert the rows (not all te rows, just a representative sample). Only then can I (or anyone else) design a SELECT statement against that table that will return the data in the form you require. It is not possible to select something from nothing.
|
|
|
|
| Re: COLUMN TO ROW & ROW TO COLUMN [message #563948 is a reply to message #563931] |
Sat, 18 August 2012 13:24   |
 |
matthewmorris68
Messages: 133 Registered: May 2012 Location: Orlando, FL
|
Senior Member |
|
|
Try this:
CREATE TABLE twisted
(
"JOBNAME" VARCHAR2(60 BYTE),
"LAST_RUN_DATE" DATE,
"CHANNEL" VARCHAR2(60 BYTE),
"SUB_CHANNEL" VARCHAR2(60 BYTE),
"PCODE" VARCHAR2(60 BYTE),
"SALES" NUMBER,
"OTHER_OUTFLOWS" NUMBER,
"DISBURSEMENTS" NUMBER,
"MVA_OUTFLOWS" NUMBER
);
SELECT 'SALES', last_run_date, channel, sub_channel, pcode,
sales AS FACT_TRANSACTION,
sales AS FACT_TRANSACTION_DETAIL,
sales AS FACT_FLOW_AGGREGATE
FROM twisted
UNION
SELECT 'OTHER_OUTFLOWS', last_run_date, channel, sub_channel, pcode,
OTHER_OUTFLOWS AS FACT_TRANSACTION,
OTHER_OUTFLOWS AS FACT_TRANSACTION_DETAIL,
OTHER_OUTFLOWS AS FACT_FLOW_AGGREGATE
FROM twisted
UNION
SELECT 'DISBURSEMENTS', last_run_date, channel, sub_channel, pcode,
DISBURSEMENTS AS FACT_TRANSACTION,
DISBURSEMENTS AS FACT_TRANSACTION_DETAIL,
DISBURSEMENTS AS FACT_FLOW_AGGREGATE
FROM twisted
UNION
SELECT 'MVA_OUTFLOWS', last_run_date, channel, sub_channel, pcode,
MVA_OUTFLOWS AS FACT_TRANSACTION,
MVA_OUTFLOWS AS FACT_TRANSACTION_DETAIL,
MVA_OUTFLOWS AS FACT_FLOW_AGGREGATE
FROM twisted;
|
|
|
|
|
|
|
|
|
|
|
|
| Re: COLUMN TO ROW & ROW TO COLUMN [message #563965 is a reply to message #563959] |
Sun, 19 August 2012 00:57  |
 |
Michel Cadot
Messages: 54672 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Query with generator equivalent to matthewmorris68's one:
with lines as (select level line from dual connect by level <= 4)
select decode(line, 1,'SALES', 2,'OTHER_OUTFLOWS', 3,'DISBURSEMENTS', 4,'MVA_OUTFLOWS') "TYPE",
last_run_date, channel, sub_channel, pcode,
decode(line, 1,sales , 2,OTHER_OUTFLOWS, 3,DISBURSEMENTS, 4,MVA_OUTFLOWS) FACT_TRANSACTION,
decode(line, 1,sales , 2,OTHER_OUTFLOWS, 3,DISBURSEMENTS, 4,MVA_OUTFLOWS) FACT_TRANSACTION_DETAIL,
decode(line, 1,sales , 2,OTHER_OUTFLOWS, 3,DISBURSEMENTS, 4,MVA_OUTFLOWS) FACT_FLOW_AGGREGATE
from twisted, lines
/
Regards
Michel
|
|
|
|
Goto Forum:
Current Time: Tue Jun 18 19:42:18 CDT 2013
Total time taken to generate the page: 0.11077 seconds
|