Transpose columns to rows
HI All,
I want to transpose columns to rows in my reports. I tried through Pivot Table and i was able to do that, but columns name are not appearing in the left.
Plz help me out how to do that with column name/
Can we do the same with measure also???
Thanks
All, thanks for the information.
I have a similar requirement as being discussed here. However, I do not have any measures in my report. It is a plain request which fetches data in three columns A, B and C (and variable number of rows depending on the data available).
Can I still use pivot table to transpose this data such that the resultant display would have three rows always and variable number of columns, with the first column containing the header A, B and C ? If yes, how do I go about it? Else, is there any other approach?
Thanks again
I
Edited by: user635102 on Sep 18, 2008 12:31 PM
Similar Messages
-
Transpose columns and rows in numbers
I need to transpose columns and rows in Numbers and I do not want to write script to do it. Is there an easier way?
Give me a proper transpose and I will uninstall Excel and never look back.
Ok, here's a proper transpose, that can be placed in an Automator Service so it becomes a simple menu pick as below (and can also be assigned a keyboard shortcut).
To use it (this is slightly different from Excel) you select the range you want to transpose, choose Copy Transpose, click a destination cell in an existing table in the current document or another document, and command-v (Edit > Paste) or option-shift-command-v (Edit > Paste and Match Style).
The one-time setup is as follows. In Automator choose File > New > Service, drag a Run AppleScript action from the left into the right pane, choose 'No Input' for 'Services receives selected' and 'Numbers' for 'in'. Then paste the following into the Run AppleScript action, replacing all text already there by default:
--Transpose - select range, run, paste transposed values where wanted
try
tell application "Numbers" to tell front document to tell active sheet
set selected_table to first table whose class of selection range is range
tell selected_table
set my_selection to the selection range
set first_col to address of first column of my_selection
set last_col to address of last column of my_selection
set first_row to address of first row of my_selection
set last_row to address of last row of my_selection
set str to ""
repeat with i from first_col to last_col
repeat with j from first_row to last_row
set str to str & (value of cell j of column i of selected_table) & tab
end repeat
set str to str & return -- add line return after row
end repeat
end tell
end tell
set the clipboard to str
display notification "Ready to paste transposed values" with title "Numbers"
on error
display dialog "Select a range first and then try again"
end try
--end script
Hit the compile "hammer" and the script should indent properly. Then save the service with the name you want to appear in your menu, and it will thereafter be available via the Services menu (and keyboard shortcut, if you set one up in System Preferences > Keyboard > Shortcuts > Services).
That's it. Less then five minutes' one-time set-up work and you've got a menu pick for a transpose functionality that is as convenient as Excel's.
SG -
How to transpose columns to rows in ODI
Hi,
I am trying to transpose Columns to rows along with Headers. For instance if i have
Account Name | Assigned To | Lead Source | Currency | Onsite_April |Offisite_April2 | FCST AMC LIC April
| | | | | |
Microsoft | Mark | Channel1 | INR | 1000 | 2000 | 3000
Then i need in the below way
Account Name | Assigned To | Lead Source | Currency | Month | Amount
| | | | |
Microsoft | Mark | Channel1 | INR | Onsite_April | 1000
Microsoft | Mark | Channel1 | INR | Offisite_April2 | 2000
Microsoft | Mark | Channel1 | INR | FCST AMC LIC April | 3000
Is there any specific function where i can achieve this?
More over i need break up Month column into two i.e Onsite_April will be Onsite (in one column) April (in another column).Hi
here is what i got by using the above KM
create table cad_temp_1(item_id number, location_id number, sales_date_ud1 varchar2(100), qty_ud2 number);
create table cad_temp_2(item_id number, location_id number, D01012010 number, D01022010 number);
insert into cad_temp_2 values(1,1,200,300);
commit;
Source in interface is : cad_temp_2
Target is: cad_temp_1
Mapping is
Item_id - Item_id execute on: CAD_TEMP_2 (Source selected) Update - Insert and Update checked
Location_id - Location_id execute on: CAD_TEMP_2 (Source selected) Update - Insert and Update checked
sales_date_ud1 - :NA execute on: <null> (Target selected) Update - Insert, Update, UD1 selected
qty_ud2 - :NA execute on : <null> (Target selected) Update - Insert, Update, UD2 selected.
Execute the interface
It works.
Thanks
Bhaskar -
Transposing columns to rows in excel through ODI
Hi all,
We are trying to transpose Columns to rows along with Headers considering excel as source and oracle table as target
For example we are having metadata and data in Excel sheet like below
Metadata:- A,B,TC1,TD1,L1,U1,TC2,TD2,L2,U2,TC3,TD3,L3,U3
Data:- X,Y,1,2,3,4,5,6,7,8,9,10,11,12
M,N,a,b,c,d,e,f,g,h,i,j,k,l
Then we need in the below way in oracle table
A,B,TC1,TD1,L1,U1
X,Y,1,2,3,4
X,Y,5,6,7,8
X,Y,9,10,11,12
M,N,a,b,c,d
M,N,e,f,g,h
M,N,i,j,k,l
Is there any process to achieve this?
If so Please let us know
Thanks in advanceHi SH,
Thanks for your reply
We already tried http://s3.amazonaws.com/Ora/KM_IKM_Pivot.zip by following the link https://community.oracle.com/thread/904535?tstart=0
But unfortunately we got the same error which is mentioned in that link
org.apache.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<string>", line 35, in ?
java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
I am newbie to odi - if possible can you please guide me how to do transpose in odi by considering excel as source and oracle as target
Thanks -
hi ,
i need to transpose columns into rows ,
i know i can use the UNION ALL but my num of columns will most likely not be fixed so how can i do that ?
pls adviseThis is from one of the forms link,, i reallyy dont know the link, but i guess this is "adrains" code
SQL> WITH ilv AS (
2 SELECT str || ',' AS str
3 , (LENGTH(str) - LENGTH(REPLACE(str, ','))) + 1 AS no_of_elements
4 FROM t
5 )
6 SELECT RTRIM(str, ',') AS original_string
7 , SUBSTR(str, start_pos, (next_pos-start_pos)) AS single_element
8 , element_no
9 FROM (
10 SELECT ilv.str
11 , nt.column_value AS element_no
12 , INSTR(
13 ilv.str,
14 ',',
15 DECODE(nt.column_value, 1, 0, 1),
16 DECODE(nt.column_value, 1, 1, nt.column_value-1)) + 1 AS start_pos
17 , INSTR(
18 ilv.str,
19 ',',
20 1,
21 DECODE(nt.column_value, 1, 1, nt.column_value)) AS next_pos
22 FROM ilv
23 , TABLE(
24 CAST(
25 MULTISET(
26 SELECT ROWNUM FROM dual CONNECT BY ROWNUM < ilv.no_of_elements
27 ) AS number_ntt )) nt
28 );
ORIGINAL_STRING SINGLE_ELEMENT ELEMENT_NO
X,Y,Z X 1
X,Y,Z Y 2
X,Y,Z Z 3
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG XXX 1
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG Y 2
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG ZZ 3
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG AAAAA 4
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG B 5
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG CCC 6
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG D 7
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG E 8
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG F 9
XXX,Y,ZZ,AAAAA,B,CCC,D,E,F,GGG GGG 10
13 rows selected.
Note that the above SQL performs the following steps:
* determines how many elements are in each string (WITH clause);
* for each string, generates a collection of n elements (TABLE expression), where n is the derived number of elements in the string. Note in particular the use of "less than" in the "CONNECT BY ROWNUM < ilv.no_of_elements" on line 26. In all versions other than 10.1.x, this will need to be "CONNECT BY ROWNUM <= ilv.no_of_elements" (i.e. "less than or equal to"). There is an unusual bug with this row-generation technique in 10.1 that generates an additional row from the CONNECT BY;
* uses the generated rows in a Cartesian Product with the original data to generate n rows per string, based on the above definition of n;
* calculates the start and end position of each element in each string (INSTR); and
* cuts each element from each string (SUBSTR). -
Transpose columns and rows / Switch columns and rows
Hello,
Is it possible to interchange columns and rows in order to create a left-to-right scrolling table instead of a top-to-bottom scrolling one?
In detail:
I have this:
| col 1 | col 2 | col 3
row 1 | | |
row 2 | | |
row 3 | | |
... | | |
...and want to have this:
| row 1 | row 2 | row 3 | ...
col 1 | | | |
col 2 | | | |
col 3 | | | |
Does anyone know if this is possible with the standard table or the ALV?
Thanks in advance & Kind regards,
RobertHi,
So there is no easy solution by just setting a flag in the ALV config!? ...too bad!
As for the dynamic creation:
Would there be an issue with different data types in one "column" (former row)? As a matter of fact there probably will be a mix of character, numbers, ...
Regards,
Robert -
How to transpose columns to rows?
Hi,
here is my situation and I would love is someone could give me some help.
This is how my data is currently presented(first line represents the header, the second line represents the value:
Number A1 A2 B1 B2 C1 C2
001187 1 2 1 6 1 1
and I would need to get it into the following format:
Number A B C
001187 1 1 1
001187 2 6 1
In summary all values from columns with same start name should be transposed into one column.
Would anyone have any suggestions?Assuming you have one table that has the columns : Number A1 A2 B1 B2 C1 C2
then something like :
select number, a, b, c
from (select 1 the_order, number, a1 a, b1 b, c1 c
from table
union all
select 2 the_order, number, a2 a, b2 b, c2 c
from table)
order by number, the_order -
How to transpose columns to rows in OBIEE
Lets say I have a row of data with 3 columns as shown below.
Col1 Col1 Col3
Val1 Val2 Val3
How can this be shown as 3 rows as below
Col 1 Val1
Col 2 Val2
Col 3 Val2
Thanks.Use the Narrative View
Prefix: <table border=1>
Narrative:
<tr><td>Col1</d><td>@1</td></tr>
<tr><td>Col2</d><td>@2</td></tr>
<tr><td>Col3</d><td>@3</td></tr>
Postfix:
</table>
Enjoy! -
Transpose columns into rows-Please Help
Hi,
I have a table(test_data) in following format:
F_P reference_id first_nm last_nm
EM_NULL 0 0 0
EM_NOT_NULL 0 0 0
DM_NULL 1296 145 1689
DM_NOT_NULL 0 0 0I need to transpose the the above table as :
Column_Name EM_NULL EM_NOT_null DM_null DM_not_null
Reference_ID 0 0 1296 0
first_nm 0 0 145 0
last_nm 0 0 1689 0I tried below code but unable to get the first column values as reference_id,first_nm,last_nm although I was successful in getting the other column values.Below is the code:
With
lines as (select level line from dual connect by level <= 3),
cols as (select level col from dual connect by level <= 3)
select
max(decode(col, 1,
decode(line, 1, to_number('REFERENCE_ID') ,
2, to_number('FIRST_NM'),
3, to_number('LAST_NM')
)))column_name,
max(decode(col, 2,
decode(line, 1, REFERENCE_ID,
2, FIRST_NM,
3, LAST_NM
)))EM_NULL,
max(decode(col, 3,
decode(line, 1, REFERENCE_ID,
2, FIRST_NM,
3, LAST_NM
)))EM_NOT_NULL,
max(decode(col, 4,
decode(line, 1, REFERENCE_ID,
2, FIRST_NM,
3, LAST_NM
)))DM_NULL,
max(decode(col, 5,
decode(line, 1, REFERENCE_ID,
2, FIRST_NM,
3, LAST_NM
)))DM_NULL
from lines, cols,
(select rownum rn, TEST_DATA.* from Test_Data)
where rn = col
group by line
order by lineBut since my 1st column values are character its not allowing me the group by function.
Edited by: BluShadow on 23-Sep-2011 08:31
formatted and added {noformat}{noformat} tags.I think you want something like this...
SQL> ed
Wrote file afiedt.buf
1 with test_data as (select 'EM_NULL' as f_p, 0 as reference_id, 0 as first_nm, 0 as last_nm from dual union all
2 select 'EM_NOT_NULL', 0, 0, 0 from dual union all
3 select 'DM_NULL', 1296, 145, 1689 from dual union all
4 select 'DM_NOT_NULL', 0, 0, 0 from dual)
5 --
6 -- end of test data
7 --
8 select decode(rn,1,'Reference_ID',2,'first_nm',3,'last_nm') as Column_name
9 ,max(decode(f_p,'EM_NULL',decode(rn,1,reference_id,2,first_nm,3,last_nm))) as EM_NULL
10 ,max(decode(f_p,'EM_NOT_NULL',decode(rn,1,reference_id,2,first_nm,3,last_nm))) as EM_NOT_NULL
11 ,max(decode(f_p,'DM_NULL',decode(rn,1,reference_id,2,first_nm,3,last_nm))) as DM_NULL
12 ,max(decode(f_p,'DM_NOT_NULL',decode(rn,1,reference_id,2,first_nm,3,last_nm))) as DM_NOT_NULL
13 from test_data, (select rownum rn from dual connect by rownum <= 3)
14 group by decode(rn,1,'Reference_ID',2,'first_nm',3,'last_nm')
15* order by decode(Column_name,'Reference_ID',1,'first_nm',2,3)
SQL> /
COLUMN_NAME EM_NULL EM_NOT_NULL DM_NULL DM_NOT_NULL
Reference_ID 0 0 1296 0
first_nm 0 0 145 0
last_nm 0 0 1689 0Unless you're using 11g and then you could look at the new PIVOT/UNPIVOT keywords -
Unable to Transpose Columns to Rows in DataExport Command
Hi,
The Data export code for On and Off Gives me the same result
SET LOCKBLOCK HIGH;
SET CACHE HIGH;
SET CALCPARALLEL 3;
SET DATAEXPORTOPTIONS
DataExportLevel "LEVEL0";
DataExportColFormat ON;
DataExportOverwriteFile ON;
DataExportDimHeader OFF;
DataExportRelationalFile ON;
DataExportColHeader "Scenario";
FIX ("SAP",&CurrFcst,&Currmnth:Sep,"Forecast Employees",&CurrFY,@IDescendents("All_Cost_Center"),@IDescendents("Pay Type"),@IDescendents("Work Type"),@IDescendents("Other_Accounts")
DATAEXPORT "File" "," $DataExportPath "0";
ENDFIX;
ENDFIX;
Result
WT"|"Non-Exempt"|7|5|5|5|5|4|4|4|4|4
"SAP"|"FY13"|"Plan"|"A100C30100"|"Forecast Employees"|"Full-Time"|"Indirect WT"|"Exempt"|3|3|3|3|3|3|3|3|3|3
"SAP"|"FY13"|"Plan"|"A100C30110"|"Forecast Employees"|"Full-Time"|"Direct WT"|"Exempt"|8|6|6|6|6|6|6|6|6|6
"SAP"|"FY13"|"Plan"|"A100C30120"|"Forecast Employees"|"Full-Time"|"Direct WT"|"Exempt"|7|4|4|4|4|4|4|4|4|4
"SAP"|"FY13"|"Plan"|"A100C30130"|"Forecast Employees"|"Full-Time"|"Direct WT"|"Exempt"|4|4|4|4|4|4|4|4|4|4
"SAP"|"FY13"|"Plan"|"A100C30160"|"Forecast Employees"|"Full-Time"|"Indirect WT"|"Exempt"|5|4|4|4|4|3|3|3|3|3
The way that i want the Data to be Represented is
SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Jan" 5.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Feb" 5.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Mar" 5.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Apr" 5.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "May" 4.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Jun" 4.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Jul" 4.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Aug" 4.0000
"SAP" "Plan" "Forecast Employees" "FY13" "A100C20270" "Non-Exempt" "Direct WT" "Full-Time" "Sep" 4.0000
I believe that this issue is because of the Range that is used (&Currmnth:Sep)
Could Someone help on this Issue.
Thanks,
JoeI hope below code will give you result desired format, changes I made are in bold and italics
SET LOCKBLOCK HIGH;
SET CACHE HIGH;
SET CALCPARALLEL 3;
SET DATAEXPORTOPTIONS
DataExportLevel "LEVEL0";
DataExportColFormat OFF;
DataExportOverwriteFile ON;
DataExportDimHeader OFF;
DataExportRelationalFile ON;
+/*DataExportColHeader "Scenario"*/+;
FIX ("SAP",&CurrFcst,&Currmnth:Sep,"Forecast Employees",&CurrFY,@IDescendents("All_Cost_Center"),@IDescendents("Pay Type"),@IDescendents("Work Type"),@IDescendents("Other_Accounts")
DATAEXPORT "File" "," $DataExportPath "0";
ENDFIX;
ENDFIX; -
Hi there,
Context:
I have to run a job weekly which would load (update/insert) DestTable with data from SourceTable, before i load the data into DestTable i have to transform the data which includes transpose Columns to rows based on a composite key and calculate to derive few columns. I have written this job in .net exe but it is taking huge amount of time to finish the job, like it took 5hours to process 1.9 million records.
SourceTable has a similar structure
ColName
Item_id
sales
Item_desc
profit
state_code
DestTable has a similar structure
ColName
Item_id
Sales_for_state1
sales_for_state2
sales_for_state3
sales_for_state4
profit
profit_margin --this is calculated based on the above columns
the above is just a glimpse of the tables' structure that i have to process.
Resolution:
I would like to rewrite the .net exe code into a PL/SQL. can you help me write a query that would transform the columns to rows and calculate and then insert them in to the DestTable.
ThanksAs far as I understand your structure, it's not a pivot-like thing. So, probably, you can make a transformation of the following kind. And then directly upload to the target_table:
select item_id,
sum(decode(state_code,'CODEOFSTATE1',sales, null)) s4state1,
sum(decode(state_code,'CODEOFSTATE2',sales, null)) s4state2,
sum(decode(state_code,'CODEOFSTATE3',sales, null)) s4state3,
sum(decode(state_code,'CODEOFSTATE4',sales, null)) s4state4,
sum(profit)
from source_table
group by item_id -
How to Transpose series of rows & columns to singular inline column?
Hi gang!
Looking to do the reverse of my previous post (here: http://discussions.apple.com/message.jspa?messageID=9355192#9355192).
Specifically, looking to transpose from many rows & columns to 1 inline column...
from:
A1 A2 A3 A4 A5 A6 A7
B1 B2 B3 B4 B5 B6 B7
to:
A1
A2
A3
A4
A5
A6
A7
B1
B2
B3
B4
B5
B6
B7
For a whole set of data (over 330 rows of 7 columns)!
A function for doing the inverse was graciously provided in the previous post, but am stuck as to how to reverse it!
Previous (from 1 column to many):
INDEX(TRANSPOSE('Table_Src' :: B2:H2),7,1*(ROW()-2)+COLUMN()-1)
becomes... (from many to 1 column)
Anyone with ideas? Found the Function guide only more confusing! :OI would use this simple script:
--[SCRIPT] on run
set {rname, tName, sName, dName, colNum1, rowNum1, colNum2, rowNum2} to my getSelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
set liste to {}
repeat with r from rowNum1 to rowNum2
repeat with c from colNum1 to colNum2
copy value of cell r of column c to end of liste
end repeat
end repeat
end tell
set liste to my recolle(liste, return)
set the clipboard to liste
end run
--=====
on getSelParams()
local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
if my parleAnglais() then
if r_Name is missing value then error "No sheet has a selected table."
else
if r_Name is missing value then error "Aucune feuille ne contient une table sélectionnée."
end if
set two_Names to my decoupe(r_Name, ":")
tell application "Numbers" to tell document d_Name to tell sheet s_Name to tell table t_Name
set col_Num1 to address of column of cell (item 1 of two_Names)
set row_Num1 to address of row of cell (item 1 of two_Names)
if item 2 of two_Names = item 1 of two_Names then
set {col_Num2, row_Num2} to {col_Num1, row_Num1}
else
set col_Num2 to address of column of cell (item 2 of two_Names)
set row_Num2 to address of row of cell (item 2 of two_Names)
end if
end tell -- _Numbers …
return {r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2}
end getSelParams
--=====
set {r_Name, t_Name, s_Name, d_Name} to my getSelection()
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theRange, theTable, theSheet, theDoc}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on recolle(l, d)
local t
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to ""
return t
end recolle
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]
Select the range to transpose
Run the script
paste where you want.
Yvan KOENIG (from FRANCE lundi 4 mai 2009 15:17:08) -
Need some help to display the output data in the below format,Pls help out...
Eg:
OV:Old Value
NV:New Value
ID OV NV
1 -- 100
1 100 200
1 200 300
OUTPUT:
ID VALUES
1 100 200 300Hi,
i think this link helpful to you
http://www.club-oracle.com/forums/unpivoting-column-to-row-conversion-techniques-sql-t145/ -
Transpose of columns to rows (unpivoting) and not rows to columns
Hi,
I am right now using oracle 10g. I HAVE the following specification. Here I specified only 5 columns.
We have upto 200 columns.
TRANS_ID PORTFILIO_NUM TICKER PRICE NUM_SHARES ........................................
2 100 MO 25.00 100 ........................................
3 100 MCD 31.50 100 ........................................
I want the above to be transformed into the following output .
TRANS_ID TYPE VALUE
2 PORTFILIO_NUM 100
2 TICKER MO
2 PRICE 25.00
2 NUM_SHARES 100.
I don't want to use case/decode function by hard coding the 200 columns.
Can anyone provide me a good way (mostly dynamic way) of doing this?
I searched the whole forum and also other forums. Everywhere I could find
rows to columns / columns to rows where the column names have been hardcoded.
I want a dynamic way of doing it. Let me know if u need any other inputs.
DDL :
CREATE TABLE PORT_TRANS
TRANS_ID VARCHAR2(100 BYTE),
PORTFILIO_NUM VARCHAR2(100 BYTE),
TICKER VARCHAR2(100 BYTE),
PRICE VARCHAR2(100 BYTE),
NUM_SHARES VARCHAR2(100 BYTE)
INSERT INTO PORT_TRANS (TRANS_ID,PORTFILIO_NUM,TICKER,PRICE,NUM_SHARES)
VALUES('2','100','MO','25.00','100');
INSERT INTO PORT_TRANS (TRANS_ID,PORTFILIO_NUM,TICKER,PRICE,NUM_SHARES)
VALUES('3,'100','MCD','31.50','100');
COMMIT;
Thanks,
Priya.Hi,
What you're trying to write is something like this:
WITH cntr AS
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <= 4
SELECT p.trans_id
, CASE
WHEN c.n <= 2
THEN
CASE c.n
WHEN 1 THEN 'PORTFILIO_NUM'
WHEN 2 THEN 'TICKER'
END
ELSE
CASE c.n
WHEN 3 THEN 'PRICE'
WHEN 4 THEN 'NUM_SHARES'
END
END AS type
, CASE
WHEN c.n <= 2
THEN
CASE c.n
WHEN 1 THEN p.PORTFILIO_NUM
WHEN 2 THEN p.TICKER
END
ELSE
CASE c.n
WHEN 3 THEN p.PRICE
WHEN 4 THEN p.NUM_SHARES
END
END AS value
FROM port_trans p
CROSS JOIN cntr c
ORDER BY p.trans_id
, c.n
;I wrote this as if CASE could only handle 2 choices, rather than 128, just to show how to nest CASE expressions.
What you have to do is write the CASE expressions, based on the contents of all_tab_columns.
In your sample data, all of the columns are VARCHAR2 (another design flaw). If you have any columns of other types, use TO_CHAR to convert them to VARCHAR2; that is, the final code to be run will have something like:
... WHEN 4 THEN TO_CHAR (p.NUM_SHARES)If I had to do this, I might run several queries on all_tab_columns, each producing one script, containing just a fragment of the query.
To run the whole thing, I would hard-code a main query like this
WITH cntr AS
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <=
@num_columns.sql
SELECT p.trans_id
, CASE
@type.sql
END AS type
, CASE
@value.sql
END AS value
FROM port_trans p
CROSS JOIN cntr c
ORDER BY p.trans_id
, c.n
;As with any coidng, start small and take baby steps. Maybe the first step would just be to write num_columns.sql, which just contains the number 4. When you can do that, hard-code the CONNECT BY query, calling num_columns.sql.
Good luck! -
In Numbers, I want to make 3 rows 50 columns into 3 columns 50 rows.
In just a simple Numbers 09 spreadsheet, no charts, I'm trying to convert the rows and columns to columns and rows to more easily work with the information without scrolling across the page. I would be able to see the information on one page and more easily print a one page documents. I can't seem to figure it out; and the Help option has not been helpful unless you are working with a chart. I don't want a chart, I want to work with the spreadsheet and cells.
Any ideas! I'm sure it is operator error, but it's something I'm not familiar with. I'm new to Apple and definitely new to numbers.
Thanks,
SandraYou may go to my iDisk (address below)
download :
For_iWork:iWork '09:for_Numbers09:Transpose.zip
Expand the archive
You will get two scripts.
One which transpose the values
One which transpose keeping formulas if the original table is a living one.
Yvan KOENIG (VALLAURIS, France) samedi 8 octobre 2011 09:29:28
iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
My iDisk is : <http://public.me.com/koenigyvan>
Please : Search for questions similar to your own before submitting them to the community
Maybe you are looking for
-
How to set up icloud for family and one itunes account
I just got a new disk drive in my MACbook (now upgraded to Mountain Lion) so starting from scratch with itunes. With 4 IOS devices in the family and only one itunes account, I would like to figure out how to backup every device to itunes. I was
-
i use the firefox4, and when i went to my history, i right clicked to delete a certain site, and accidentally hit the last option; (forget about this site) which deleted all the similar sites to the one i clicked! i.e. if it were facebook site, all f
-
Company Code Payment Details missing on dunningletter
Hi Expert, I have two issues regarding dunning letter. One is Company Code Payment Details missing on dunningletter anthor one is Missing dunning letter for 2nd and 3rd dunning level Could you please help us how to slove the issues.
-
Encrypt External Drive with TrueCrypt / PGP Signature
I want to use TrueCrypt to encrypt an external drive. I understand the new version of FileVault can do this but I prefer not to upgrade to Lion. I'd rather wait till Mountain Lion comes out later this year. For those who have used both...Just wonderi
-
IdentitySSOAuthFilter error with "uwc-msg-web-amsdk" in a Sol 10 zone
I have installed the 2005Q1 JES components (messaging, calendar, Access Manager, LDAP, Web, and UWC with SSO) in a single Solaris 10 zone without any issues. All works fine. I'm having an UWC/Web error in the next step of the process when I'm install