Row to Column conversion
Hi,
i am having following table
SELECT* FROM Col_to_row;
output is:
A B C
X Y Z
1 2 3
i want to write query for below output, need to convert row into column for n number of rows for example i have taken only 3 rows:
A X 1
B Y 2
C Z 3
Three things to notice in this solution:
1) I am ordering by the original column name. You may want to order by something else.
2) When pivoting, you must indicate the name, number and datatype of the columns, so if there is a fourth line of input you have to add a column to the query.
3) This works on Oracle 11GR1 and above. Next time, be sure to indicate your Oracle version from the start.create table COL_TO_ROW(C1, C2, C3) as select
'A', 'B', 'C' from DUAL union all select
'X', 'Y', 'Z' from DUAL union all select
'1', '2', '3' from dual;
select * from (select rownum rn, a.* from COL_TO_ROW a)
UNPIVOT(VAL for COL in(C1, C2, C3))
PIVOT(max(VAL) for RN in (1,2,3))
order by col;
COL 1 2 3
C1 A X 1
C2 B Y 2
C3 C Z 3
Similar Messages
-
Rows to Column Conversion in ABAP
Hello guys,
I wanted to create a report in which I need to convert rows in to column.
e.g.
I have a itab_col which contains my column header as follows.
itab_col-plant itab_col-name
1000 Plant A
2000 Plant B
3000 Plant C
I have a itab_data which contains my data as follows .
itab_data-date itab_data-qty itab_data-plant
01.06.2006 10 1000
01.06.2006 20 1000
01.06.2006 50 2000
02.06.2006 20 3000
I need to print the report as follows
Date Plant A Plant B Plant C
01.06.2006 30 50 0
02.06.2006 0 0 20
Could you tell me how I can do it in abap.Hi,
first create table with following attribute.
table_row_to_column
1. date
2. Plant A
3. Plant B
4. Plant C.
.............D E F ..number of plant possible.
Sum Up The data
01.06.2006 10 1000
01.06.2006 20 1000
01.06.2006 50 2000
02.06.2006 20 3000
01.06.2006 30 1000
01.06.2006 50 2000
02.06.2006 20 3000
to new data_table_sum_value
<b>for that u have to</b>
1) Sort the table date & plant.
2) sum up records for similar plant based on date
<b>Convert rows in to column.</b>
loop at data_table_sum_value.
case data_table_sum_value-plant.
when 1000.
table_row_to_column-plant_A = data_table_sum_value-qnty.
when 2000.
table_row_to_column-plant_B = data_table_sum_value-qnty.
when 3000.
table_row_to_column-plant_C = data_table_sum_value-qnty.
when 4000.
table_row_to_column-plant_D = data_table_sum_value-qnty.
when 5000.
table_row_to_column-plant_E = data_table_sum_value-qnty.
endcase.
at end of date.
append table_row_to_column.
endat.
endloop.
<b>Please Mark Helpful Answers & Rewards Points.
Dont Forget to mark as problem solved if solved</b>
Regards -
Row to column conversion during excel download
Dear Experts,
I have an internal table with one column.
It has some entries say ten.
I want this ten rows of entries to be displayed in the excel sheet as a single row. It means each row entry of the internal table should fit in to each cell.
Is there any possibility with GUI_DOWNLOAD FM to do this?
If not, then how could i do that?
Please let me know its urgent.
Regards,
ShashiHi,
i m not aware of whether it can be done through FM 'GUI_DOWNLOAD' but i have one sugeestion.
You can first transpose your internal table and then download it.
Sample code for obtaining the transpose is as follows:
*& Report Z_TRANPOSEALV *
*& Author : Swarna.S.
*& AS: This simple ALV report display is in a transposed way
*& Publised at ****************
REPORT Z_TRANSPOSEALV .
Type pools declaration for ALV
TYPE-POOLS: slis.
*Declarations for ALV, dynamic table and col no for transpose
DATA: l_col TYPE sy-tabix,
l_structure TYPE REF TO data,
l_dyntable TYPE REF TO data,
wa_lvc_cat TYPE lvc_s_fcat,
lt_lvc_cat TYPE lvc_t_fcat,
lt_fieldcatalogue TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_layout TYPE slis_layout_alv.
*Field symbols declarations
FIELD-SYMBOLS :
<header> TYPE ANY,
<dynheader> TYPE ANY,
<dyndata> TYPE ANY,
<ls_table> TYPE ANY,
<dynamictable> TYPE STANDARD TABLE,
<it_table> TYPE STANDARD TABLE.
*Input the name of the table
PARAMETERS p_table TYPE dd02l-tabname OBLIGATORY.
*Initialization event
INITIALIZATION.
*Start of selection event
START-OF-SELECTION.
Create internal table of dynamic type
CREATE DATA l_dyntable TYPE STANDARD TABLE OF (p_table)
WITH NON-UNIQUE DEFAULT KEY.
ASSIGN l_dyntable->* TO <it_table>.
*select statement to select data from the table as input into
*our dynamic internal table.
*Here i have restricted only till 5 rows.
*You can set a variable and give no of rows to be fetched
*The variable can be set in your select statement
SELECT * INTO CORRESPONDING FIELDS OF TABLE <it_table>
FROM (p_table) up to 5 rows.
*Fieldcatalogue definitions
wa_lvc_cat-fieldname = 'COLUMNTEXT'.
wa_lvc_cat-ref_table = 'LVC_S_DETA'.
APPEND wa_lvc_cat TO lt_lvc_cat.
wa_fieldcat-fieldname = 'COLUMNTEXT'.
wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
wa_fieldcat-key = 'X'..
APPEND wa_fieldcat TO lt_fieldcat.
DESCRIBE TABLE <it_table>.
DO sy-tfill TIMES.
For each line, a column 'VALUEx' is created in the fieldcatalog
Build Fieldcatalog
WRITE sy-index TO wa_lvc_cat-fieldname LEFT-JUSTIFIED.
CONCATENATE 'VALUE' wa_lvc_cat-fieldname
INTO wa_lvc_cat-fieldname.
wa_lvc_cat-ref_field = 'VALUE'.
wa_lvc_cat-ref_table = 'LVC_S_DETA'.
APPEND wa_lvc_cat TO lt_lvc_cat.
Build Fieldcatalog
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = wa_lvc_cat-fieldname.
wa_fieldcat-ref_fieldname = 'VALUE'.
wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
APPEND wa_fieldcat TO lt_fieldcat.
ENDDO.
Create dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_lvc_cat
IMPORTING
ep_table = l_dyntable. ASSIGN l_dyntable->* TO <dynamictable>.
Create structure as structure of the internal table
CREATE DATA l_structure LIKE LINE OF <dynamictable>.
ASSIGN l_structure->* TO <header>.
Create structure = structure of the internal table
CREATE DATA l_structure LIKE LINE OF <it_table>.
ASSIGN l_structure->* TO <ls_table>.
Create field catalog from our table structure
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_table
CHANGING
ct_fieldcat = lt_fieldcatalogue
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. DESCRIBE TABLE lt_fieldcatalogue.
Fill the internal to display <dynamictable>
DO sy-tfill TIMES.
IF sy-index = 1.
READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX 1.
ENDIF.
For each field of it_table
ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <dynheader>.
IF sy-subrc NE 0. EXIT .ENDIF.
READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX sy-index.
Fill 1st column
<dynheader> = wa_fieldcat-seltext_m.
IF <dynheader> IS INITIAL.
<dynheader> = wa_fieldcat-fieldname.
ENDIF.
*Filling the other columns
LOOP AT <it_table> INTO <ls_table>.
l_col = sy-tabix + 1.
ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO <dyndata>.
IF sy-subrc NE 0. EXIT .ENDIF.
ASSIGN COMPONENT l_col OF STRUCTURE <header> TO
<dynheader>.
IF sy-subrc NE 0. EXIT .ENDIF.
WRITE <dyndata> TO <dynheader> LEFT-JUSTIFIED.
ENDLOOP.
APPEND <header> TO <dynamictable>.
ENDDO.
*Layout for ALV output
lt_layout-zebra = 'X'.
lt_layout-no_colhead = 'X'..
lt_layout-colwidth_optimize ='X'.
lt_layout-window_titlebar = 'ALV GRID TRANSPOSED'.
*ALV Grid output for display
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = lt_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = <dynamictable>.
Regards,
Karuna. -
Row to column conversion in large result set
I need to get the differnt levels of alerts for each user, with the total alert counts and counts for each type of alert.
SELECT COUNT(*) TOTAL,
u.name,
d.deptname,
COUNT(CASE WHEN al.severity = 5 THEN 1 END) INDETERMINATE,
COUNT(CASE WHEN al.severity = 4 THEN 1 END) WARNING,
COUNT(CASE WHEN al.severity = 3 THEN 1 END) MINOR,
COUNT(CASE WHEN al.severity = 2 THEN 1 END) MAJOR,
COUNT(CASE WHEN al.severity = 1 THEN 1 END) CRITICAL
FROM alerts al, user u, dept d
WHERE al.userid = u.userid
AND u.deptid = d.deptid
AND al.time = sysdate - 4/24
AND al.time <= sysdate
GROUP BY u.name, d.deptname This might be inefficient especially when the amount of data is huge and potentially you could be looking at millions of rows in a given interval. So I was thinking of grouping by severity, which would eliminate the CASE statements, but then the problem on group by is that I get it as a rows instead of columns.
Would anyone have a suggestion as to do it effeciently especially one that has millions of rows? Thanks.I guess eventually we are probably going to move towards that, but using a staright forward query is the immediate solution and any help on that would be great. Thanks.
-
Reg:Row to column conversion
Hi All,
I will give string three string values in a single variable like CNTNS_VAL_STR = test,value,small
but i need result like
test
value
small
Please help to reslove the one
thanks,Your requirement isn't very clear anymore.
Please post a small testcase, like I did below, assuming you're looking for a way to query column values based on an input string:
SQL> create table t as
2 select 1 rn,'A' descr from dual union
3 select 2,'B' from dual union
4 select 3,'C' from dual union
5 select 4,'Q' from dual union
6 select 5,'X' from dual;
Table created.
SQL> select * from t;
RN D
1 A
2 B
3 C
4 Q
5 X
5 rows selected.
SQL> create or replace function str2tbl( p_str in varchar2, p_delim in varchar2 default ',' )
2 return sys.odcivarchar2list
3 pipelined
4 as
5 l_str long default p_str || p_delim;
6 l_n number;
7 begin
8 loop
9 l_n := instr( l_str, p_delim );
10 exit when (nvl(l_n,0) = 0);
11 pipe row( ltrim(rtrim(substr(l_str,1,l_n-1))) );
12 l_str := substr( l_str, l_n+1 );
13 end loop;
14 return;
15 end;
16 /
Function created.
SQL> select *
2 from t
3 where descr in ( select column_value
4 from table(str2tbl('A,B,C'))
5 );
RN D
1 A
2 B
3 C
3 rows selected.
So, I more or less 'joined' a table to a pipelined function (no cursor needed) based on an input string.
If you search for 'str2tbl' on http://asktom.oracle.com then you'll find many more examples. -
Hi,
I know this question has been asked couple of times but I could not understand from them hence posting my query here.
I have a table named XYX
id attr_cd value
1 ABC 1000
1 PQR 2000
1 XDR 1500
2 PQR 1405
2 ABC 1254
etc
My reqt is to write a procedure which will accept ID as i/o parameter and will populate another temp table temp as
id ABC XDR PQR
1 1000 1500 200
2 1254 1405
like that.
Please comeone suggest a SIMPLE way to do that.
Thanks in advance
AashishCould you please provide a simple code which can be understood?Not sure if it can be understood, but for academical reasons it might be useful ;)
SQL> with t as (
select 1 id, 'ABC' attr_cd, 1000 value from dual union all
select 1, 'PQR', 2000 from dual union all
select 1, 'XDR', 1500 from dual union all
select 2, 'PQR', 1405 from dual union all
select 2, 'ABC', 1254 from dual
select id,
extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="ABC"]/@VALUE') abc,
extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="PQR"]/@VALUE') pqr,
extractvalue(xmlagg(xmlelement(e, xmlattributes(value), attr_cd)), 'E[text()="XDR"]/@VALUE') xdr
from t group by id
ID ABC PQR XDR
1 1000 2000 1500
2 1254 1405
2 rows selected. -
Row to Column Conversion Question
Hi All,
Could you please help on this sql query statement:
SELECT BENEFIT FROM TEST_T ;
BENEFIT
QO,1G,1U,1W
Out Put Needed like this
BENEFIT
QO
1G
1U
1W
Thanks,Hi,
As I said, it depends on your data, your requirements and your version.
REGEXP_COUNT was new in Oracle 11.1. Since you're using an earlier version, you can see how many comma-delimited sub-strings you have by seeing how much shorter the string gets if you remove all the commas:
1 + LENGTH (benefit)
- LENGTH (REPLACE (benefit, ','))
This assumes you don't have data with mutiple consecutive commas such as 'AB,,,,CD', but it might not cause any terrible results even if you do.
The way I used CONNECT BY won't work in Oracle 10, either.
Now I know everything I need to know about your Oracle version, but I don't know anything about your data or your requirements. Do you want me to spend my time writing solutions that assume things about your data and your requirments, so you can spend your time trying them only to see that they don't do what you need?
Explain what your data is like. Do you have a fixed number of comma-delimited parts (e.g., always 4 parts). If not, do you have an upper bound (e.g., never more than 10 parts)? Can you have multiple consecutive commas?
Explain what you need to get from that data. Will you always be splitting one string into parts, as in the example you posted, or will you need to split multiple stings in the same query? Will the correct results ever contain NULL?
Post a little sample data (CREATE TABLE and INSERT statements), showing all special cases you need to handle. Post the results you want from that data.
See the forum FAQ: https://forums.oracle.com/message/9362002 -
Rows to Columns conversion in an Internal Table
Hello All,
I have data like below:
Matnr1 ABC 100
Matnr1 ABC 200
Matnr1 ABC 500
Matnr2 XYZ 300
Matnr2 XYZ 600
I want data like this:
Matnr1 ABC 100 200 500
Matnr2 XYZ 300 600
Is it possible? If yes, could anybody help achieving this?
Thanks a lot in advance.
AjayHi Ajay,
Try this.
( this is temp table for your formate)
data: begin of itab1 occurs 10,
line(150),
end of itab1.
Sort itab by col1 col2. ( Here itab is your table )
loop at itab.
at new col2.
write: / itab-col1,
itab-col2.
concatenate itab-col1
itab-col2
into itab1.
endat.
write itab-col3.
concatenate itab1
itab-col3
into itab1.
at end.
append itab1.
clear itab1.
endat.
endloop.
loop at itab1.
write / itab1.
endloop.
Plzzz Reward if useful,
Mahi.
Message was edited by:
Maheswari Chegu -
Hi,
I have a file where fields are wrapped with ".
=========== file sample
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
==========
I am having a .net method to remove the wrap characters and write out a file without wrap characters.
======================
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
======================
the .net code is here.
========================================
public static string RemoveCharacter(string sFileName, char cRemoveChar)
object objLock = new object();
//VirtualStream objInputStream = null;
//VirtualStream objOutStream = null;
FileStream objInputFile = null, objOutFile = null;
lock(objLock)
try
objInputFile = new FileStream(sFileName, FileMode.Open);
//objInputStream = new VirtualStream(objInputFile);
objOutFile = new FileStream(sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString(), FileMode.Create);
//objOutStream = new VirtualStream(objOutFile);
int nByteRead;
while ((nByteRead = objInputFile.ReadByte()) != -1)
if (nByteRead != (int)cRemoveChar)
objOutFile.WriteByte((byte)nByteRead);
finally
objInputFile.Close();
objOutFile.Close();
return sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString();
==================================
however when I run the bulk load utility I get the error
=======================================
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 3 (NumberOfMultipleMatches).
==========================================
the bulk insert statement is as follows
=========================================
BULK INSERT Temp
FROM '<file name>' WITH
FIELDTERMINATOR = ','
, KEEPNULLS
==========================================
Does anybody know what is happening and what needs to be done ?
PLEASE HELP
Thanks in advance
VikramTo load that file with BULK INSERT, use this format file:
9.0
4
1 SQLCHAR 0 0 "\"" 0 "" ""
2 SQLCHAR 0 0 "\",\"" 1 col1 Latin1_General_CI_AS
3 SQLCHAR 0 0 "\",\"" 2 col2 Latin1_General_CI_AS
4 SQLCHAR 0 0 "\"\r\n" 3 col3 Latin1_General_CI_AS
Note that the format file defines four fields while the fileonly seems to have three. The format file defines an empty field before the first quote.
Or, since you already have a .NET program, use a stored procedure with table-valued parameter instead. I have an example of how to do this here:
http://www.sommarskog.se/arrays-in-sql-2008.html
Erland Sommarskog, SQL Server MVP, [email protected] -
Converting from rows to columns
Converting Rows to Columns
We have one business requirment where they want to convert rows to columns. The data we are talking about is 2-3 TB of data. Data looks something in this format.
Table Structure
Date_1 Unit_Number Data_ID Data_Value
2013-01-02 00:00:00 100013 123 671
2013-01-02 00:00:00 100014 131 771
2013-01-02 00:00:00 100015 281 812
2013-01-02 00:00:00 100016 712 979
2013-01-02 00:00:00 100017 715 719
Pivoted table
Date_1 RY XY HJ KD IK GH HH KK TK RT ...
2013-01-02 00:00:00 671 771 812 979 719 979 719 980 799 79
2013-01-02 00:10:00 671 771 812 979 719 979 719 980 799 79
and so on
We are pivoting this data using query and creating view using query something like below
select a.date_1 date_1 a.unit_number system_number,
max(CASE WHEN a.data_id= 123 then a.DATA_Value END) RY,
max(CASE WHEN a.data_id= 281 then a.DATA_Value END) XY,
max(CASE WHEN a.data_id=712 then a.DATA_Value END) HJ,
max(CASE WHEN a.data_id=715 then a.DATA_Value END) KD,
max(CASE WHEN a.data_id=666 then a.DATA_Value END) IK,
max(CASE WHEN a.data_id=231 then a.DATA_Value END) GH,
max(CASE WHEN a.data_id=881 then a.DATA_Value END) HH,
max(CASE WHEN a.data_id=734 then a.DATA_Value END) KK,
max(CASE WHEN a.data_id=734 then a.DATA_Value END) TK,
max(CASE WHEN a.data_id=724 then a.DATA_Value END) TK,
from FROM table_name group by 1,2
We also tried pivot clause but still no major improvement in performance.
There are about 40 such rows that we are trying to convert into columns. We created indexes, Primary, Secondary and referencial ones to tune this overall query. Also added paritions, We find this conversion works fine for smaller query, however for larger set of data we get high CPU and IO and also often runs into spool error. The data set we are runing on this query are about 3-4 TB. There is another table where we have about 100 rows which we need to convert into one row and again size goes to 4-5 TB
Questions I have
1) Is there better way to convert columns to Rows?
2) What options can be use to reduce CPU, IO and Spool error?
3) Does Orage 11g datawarehouse any feature which will hellp us here
4) Any other appproach or design suggested here that will help us?
This design is pushed by our business due to flexibility this design offers and we are runing into performance and we are trying to make this work without impacting CPU, Spool and IO
Any suggestions would help us here, thanks for reading thisHi,
Here's one way to do that:
WITH got_times AS
SELECT MAX ( CASE
WHEN msg_line = 'LONGITUDINAL REFRESH HAS BEGUN'
THEN msg_datetime
) AS start_time
, MAX ( CASE
WHEN msg_line = 'LONGITUDINAL REFRESH HAS COMPLETED'
THEN msg_datetime
) AS end_time
FROM xxwv.xxwv_hsum_info_reports
SELECT start_time
, end_time
, (end_time - start_time) * 24 * 60 AS duration_minutes
FROM got_times
;When you run the two different (but very similar) to get the two times, you have two different WHERE clauses. You can combine those two similar queries into one, but whatever WHERE clause you have will apply to the whole query. Whenever you wish you could apply a WHERE clause just to one column, think of CASE instead. -
Converting key figures from rows to column using DSO and start routine
Hi SDNer:
I need some help to convert key figures from rows to column.
The source is DSO 1 and I am thinking about writing ABAP in the start routine to do the conversion. The target is DSO2.
Below is the more detail information with example. Basically, for each record in DSO 1 I need to create 3 records (because there are 3 KF's) and output to DSO2.
I would really appreciate some help on this.Thank you.
Tony
DSO 1 data format (SOURCE)
Period ID KF1 KF2 KF3
200702 100 300 200 750
Output to DSO 2 (TARGET)
Period ID KF LABEL
200702 100 300 KF1
200702 100 200 KF2
200702 100 750 KF3This is the code in BI 7.0.
u need to put a field "Label" in DSO1. u dont need to populate this in DSO1 but it helps the code to populate the field in DSO2.
DATA: wa_result TYPE _ty_s_sc_1,
t_result TYPE STANDARD TABLE OF _ty_s_sc_1.
DATA:counter(2) TYPE n.
LOOP AT SOURCE_PACKAGE INTO wa_result.
counter =0.
while counter < 3 .
wa_result- Period = wa_result-Period.
wa_result- ID = wa_result-ID.
if counter = 0.
wa_result- KF1 = wa_result-KF1.
wa_result- Label = 'KF1'.
elseif counter = 1.
wa_result- KF1 = wa_result-KF2.
wa_result- Label = 'KF2'.
else.
wa_result- KF1 = wa_result-KF3.
wa_result- Label = 'KF3'.
endif.
APPEND wa_result TO t_result.
counter = counter+1.
endwhile.
endloop.
CLEAR: SOURCE_PACKAGE,wa_result.
LOOP AT t_result INTO wa_result.
APPEND wa_result TO SOURCE_PACKAGE.
ENDLOOP. -
How to convert rows into column
Hi,
can any one help me how to convert rows into column by pl/sql procedure.
Thanks and Regardshttp://www.oracle.com/technology/oramag/code/tips2004/050304.html
-- dropping the sample table if exists
drop table rowstocol
-- create sample table
create table rowstocol ( name varchar2(20));
-- Inserting rows into sample table
insert into rowstocol values('Amit Zhankar');
insert into rowstocol values('Piyu Yawalkar');
insert into rowstocol values('Piyu Yawalkar');
insert into rowstocol values('Ashish Ghelani');
insert into rowstocol values('Aditi Zhankar');
insert into rowstocol values('Tom Kyte');
insert into rowstocol values('Oracle');
-- Following query should be run to create a sql. This result sql should be run to convert rows to column.
-- The following query uses just the tablename (whose data is to be converted) and name of the column (which is to be converted).
-- Example taken here is table rowstocol, column name.
SELECT cc
FROM (select decode(rn ,1 ,'Select ',null) ||' MAX (CASE WHEN dr = '|| rownum||' THEN DECODE (rn,1, col1) END) '||
decode(rn,maxr,' col1 from ','||'||chr(39)||','||chr(39)||'|| ') cc,rn,maxr
from (SELECT ROWNUM rn,count(0) over() maxr FROM rowstocol) order by rn) trows
union all
select '(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn' cc from dual;
-- The result of this query will do the reqd conversion from row to column.
-- Replace table rowstocol by your table, column name by your column.
CC
Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn
Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn;
COL1
Aditi Zhankar,Amit Zhankar,Ashish Ghelani,Oracle,Oracle,Piyu Yawalkar,Piyu Yawalkar,Tom Kyte
Edited by: bhooma on Jan 20, 2009 2:44 AM -
how can i open a PDF bank statement in "numbers" so that the rows and columns contain properly aligned data from statement?
Numbers can store pdfs pages or clippings but does not directly open pdf files. To get the bank statement into Numbers as a table I would open the bank statment in Preview (or Skim) or some pdf viewer.
Then hold the option key while selecting a column of data.
Then copy
Then switch to numbers and paste the column into a table
Then repeat for the other columns in the pdf document
It would be easier (in my opinion) to download the QFX or CSV version from your bank -
How to accessing current row report column value in Lov Query?
Hi,
which access methods (eg. bind variables, substitutions, ...) for getting the current row report column value can be used in the "Lov Query" property of a report column?
As what I know of and what I have read on the forum there are no bind variables for the report columns. For the "Link Text" property it seems that the column values exist as substitution strings (#COLUMN_NAME#). But they don't work in the Lov Query. => And would be good because of a hard parse each time the Lov query is executed.
The following post (Re: Simulating a correlated sub query in lov
is showing a solution to use package variables for temporary storage of the referenced value, but the only problem with that solution is that if a new record is added with the "Add rows to tabular form" process the package variable still contains the value from the last queried row! Is there a way (variable, APEX package, ...) to determine if the lov query is executed for a new record so that the package can return null?
I know that I could write the package in a way that the value is immediately cleared when lov_pkg.keyval is called (one time read), but then I would have to create several variables if I'm accessing the value multiple times in the query or in another query => I think an one time read solution would be very obscurely.
Thanks for your help
Patrick
http://inside-apex.blogspot.comHi Patrick,
I agree that it's a waste to continually use Ajax to go back to the server to get the contents of a dynamic select list.
There are no bind variables for any row item - but what you do have, as per my previous post, is the value of the data entered by the user in the first row. You can pass this into your application process (using get.add("VARIABLENAME", value)), which can use it to retrieve the correct LOV in your Ajax code - this will give you a "bind variable" that your process can use.
What you could do, however, is generate hidden select lists on your page - one for each possible LOV list and replace the contents of the new row's select list with the contents of the appropriate hidden select list. This is easy to do with javascript (using innerHTML functions). Obviously, though, the usefulness of this depends on the number and size of the select lists.
Even if you don't generate them to start with, you can keep a copy of any select lists returned by Ajax in the DOM for use on new rows. So, if you have retrieved a select list, you will have a copy of it in DOM which you can then copy into the new row. If you don't have the list in DOM, use Ajax to get it, store a copy of it and copy it into the new row.
Which method you use will depend on the number/size of select lists needed. If they are few in number and/or size, I would suggest generating hidden lists. If they are large, use Ajax to get them once, store them and then retrieve them from the DOM when needed.
There is another thread here where Arie recommends going to the server every time to make sure you get the most up-to-date data for the lists. If you want to follow this advice, for this reason, use get.add("VARIABLENAME", value) to pass the value to your process. If this is not an issue, you can use one of the other methods I outlined above.
Regards
Andy -
Row Selector column on Interactive Report
Hi all,
I have an interactive report based on a custom SQL query. How do I add a row selctor column so I cans select individual rows? I have also tried using a tabular form which also does not display a row selctor column. This is odd as my other tabular forms display a row selctor column.
Many thanks for you help,
ChrisChris,
Usually when someone wants a row selector, it's to choose a few rows by clicking a checkbox, then doing something with them. I'm guessing that's what you're looking for?
Martin Giffy D'Souza's [blog post|http://apex-smb.blogspot.com/2009/01/apex-report-with-checkboxes-advanced.html] explains one way to do that which should work for you. I haven't tried, it, but it looks pretty comprehensive.
Good luck,
Stew
Maybe you are looking for
-
Using a variable as an identifier
Hi, Lets say I have 5 text boxes that are named t1, t2, t3 etc. I would like to use the variable "i" in the array below as part of the identifier to populate the field is this possible to use an incrementing variable as part of the instance identifer
-
Safari Isn't Working After Upgrading to Yosemite
Hi, Just upgraded my 2010 MacBook Pro to Yosemite. Everything seems to be working except for Safari. It would open fine (just very very very slowly). But when I try to navigate to a web site, any web site, it goes completely unresponsive. I have
-
If I hardwire a new laptop to my wireless router, what steps do I need to take to find out if my router is encrypted? I have no internet connection.
-
Blocked. Cannot register
-
Setting Picture as Alert / Alarm
I want to set an alarm on my iphone to bring up a picture at the same time every day. Is this possible, either through the existing software or an app?