Row to Column display in PL/SQL
Hi All,
I have dyanamic query its display the periods.
ex: if the uesr gives the input like APR-07 to APR 08.
It will display the record like
APR-10 1200
MAR-10 1400
APR-08 2500Now i want to display the above code as
APR-10 MAR-10 - - - - - -- - - APR-08
1200 1400 2500but the column name is dynamic its not a static.
Thanks in Advance.
Cheers,
Shan
Shan wrote:
Hi 784328 ,
Pivot table we can give only static values for column right??
cheers,
ShanAny SQL must have a pre-determined number of columns in the output before any data is fetched, so you cannot easily base the number of output columns on the data itself.
One method is to use dynamic SQL to query the data first, then build up a dynamic query from that which returns the data pivoted as you require.
Another method is to interface with Oracle's ODCI interface e.g. How to pipeline a function with a dynamic number of columns?
Of course, the most correct method is to use the right tool for the right job.
In this case, what you're asking for is something that is more easily achieved by a reporting tool, as these query the data first and then format the report based on the data. SQL cannot naturally do this itself.
Similar Messages
-
hi all,
please help me with the script to achieve the following
instance_n Log_Date Records_count
test APR-06-2012 2814
test APR-05-2012 265
test APR-04-2012 127
test APR-03-2012 107440
test APR-02-2012 107362
test APR-01-2012 107330
output required as
Instance APR-06 APR-05 APR-04 APR-03 APR-02
test 2814 265 127 107440 107362
test2 2813 200 100 207330 207330
table "Log_table" structure is
intance_name varchar2
log_date date
records_count number
I want to dislay the records for 5 previous days
Thanks in advance for your help
Edited by: user11972299 on Apr 6, 2012 9:30 AM
Edited by: user11972299 on Apr 6, 2012 9:34 AMHi,
Here's one way:
WITH got_d AS
SELECT instance_n
, CASE
WHEN log_date >= TRUNC (SYSDATE) THEN 0
WHEN log_date >= TRUNC (SYSDATE) - 1 THEN 1
WHEN log_date >= TRUNC (SYSDATE) - 2 THEN 2
WHEN log_date >= TRUNC (SYSDATE) - 3 THEN 3
ELSE 4
END AS d
FROM log_table
WHERE log_date >= TRUNC (SYSDATE) - 4
AND log_date < TRUNC (SYSDATE) + 1
SELECT instance_n
, COUNT (CASE WHEN d = 0 THEN 1 END) AS today
, COUNT (CASE WHEN d = 1 THEN 1 END) AS today_minus_1
, COUNT (CASE WHEN d = 2 THEN 1 END) AS today_minus_2
, COUNT (CASE WHEN d = 3 THEN 1 END) AS today_minus_3
, COUNT (CASE WHEN d = 4 THEN 1 END) AS today_minus_4
FROM got_d
GROUP BY instance_n;
;This will work in Oracle 9 or higher. If you have Oracle 11, you could also use SELECT ... PIVOT.
To get dynamic column names (such as "APR-06", instead of the generic "TODAY") requires dynamic SQL. In SQL*Plus, that isn't very hard. -
How to convert data from rows into columns
Hi,
I have a sql table and the data looks like this
GLYEAR GLMN01 GLMN02 GLMN03 GLMN04
2007 -109712.40 6909.15 4758.72 56.88
2007 -13411.32 19132.9 -5585.07 4362.64
Where GLyear reprsents Year and GLMN01 is February, GLMN02 is March and so on,
Now i want my output to be something like this which i want to insert into another table
GLYear GLMonth GLAmount
2007 February -109712.40
2007 March 6909.15
2007 April 56.88
My new table has 3 columns, GLYear,GLMonth,GLAmount.
Can someone please help me with the select statement on how to do this, i can work with the inserts.
Thanks.I want you to check these form tread they have the same discussion as you. They will definitely solve your problem
http://blog.jontav.com/post/8344518585/convert-rows-to-columns-columns-to-rows-in-sql-server
http://dba.stackexchange.com/questions/19057/convert-rows-to-columns-using-pivot-in-sql-server-when-columns-are-string-data
http://stackoverflow.com/questions/18612326/how-to-convert-multiple-row-data-into-column-data-in-sql-server
I hope this helps you in solving your problem.
Please remember to click “Mark as Answer” on the post that has answered your question as it is very relevant to other community members dealing with same problem in seeking the right answer -
Can anybody help....SQL to display row as column and column as rows
Can anybody help in writing a SQL to display row as column and column as rows?
Thankscheck this link:
Re: Creating Views - from rows to a new column? -
How to refer a column value of a single row in conditional column display?
Hello,
does anybody have an idea, how i can refer a column value of a single row in conditional display of a column?
So my idea is, that a report has a column, which value is only displayed, when another column value of this row has a specific value.
I want to solve this problem with condition type: PL/SQL Function Body returning a boolean.
But I do not know how to refer the column value of each single row!
Thank you,
TimHere's a solution that, to me, seems easier to implement but, that's, of course, in the eye of the implementer.
Rather than using APEX to generate a link column for you, actually create the link as part of your SQL.
select '<a href="f?p=102:3:491847682940364::::P3_CONTACT_ID:' || CONTACT_ID || "><img src="/i/themes/theme_1/ed-item.gif" alt="Edit"></a>' CONTACT_LINK, ...
etc.
Test this out. You'll see that it works just like making a column a link using the column attributes.
Next, we'll change the SQL to use a DECODE statement to either display the link or nothing depending on what your criteria is. For example, let's assume you only want a link for active contacts.
select Decode( CONTACT_STATUS, 'A', '<a href="f?p=102:3:491847682940364::::P3_CONTACT_ID:' || CONTACT_ID || "><img src="/i/themes/theme_1/ed-item.gif" alt="Edit"></a>', NULL ) CONTACT_LINK, ...
etc.
This will not display the link in any rows in which the CONTACT_STATUS is not active, i.e. "A"
-Joe -
Need help in displaying Rows to Columns
Hi,
I am facing problem in displaying Rows to Columns
I am using pivot function:
select *
from
(select vendor_name
from tablea)
pivot
(count(vendor_name)
for vendor_name in ('a,b,'c'));
its working fine showing vendor_name and count
but when i want to display the output as:(How to include the Salalry column in the query?)
Name:{a b c}
Sal Total:(400,600,800}
Any help will be needful for meNot sure what you mean:
select *
from (select deptno,sal from emp)
pivot(sum(sal) for deptno in (10,20,30))
10 20 30
8750 10875 9400
SQL> SY. -
Displaying Row and Column Numbers
I see through other research on Oracle SQL Developer that I should be able to display the row and column numbers on version 1.5.4, but I don't see where to go to turn this on. Suggestions?
Suggestions?Ask in the SQL Developer forum?
-
Rows to columns/Transpose the records Query and Display output
hi ,
can anyone help me query this and transpose it to this format?
i am still a beginner in sql.
thanks for help!
Rows to columns/Transpose the records Query and Display output
id startdate endate
1111 1/2/2001 11/3/2001
1111 2/5/2002 4/3/2002
1111 2/6/2000 2/5/2001
3333 5/2/2003 11/3/2003
3333 6/2/2003 12/3/2003
3333 2/6/2005 2/5/2005
desired output
id startdate1 endate1 startdate2 endate2 startdate3 endate3
1111 1/2/2001 11/3/2001 2/5/2002 4/3/2002 2/6/2000 2/5/2001
3333 5/2/2003 11/3/2003 6/2/2003 12/3/2003 2/6/2005 2/5/2005Have you only 3 dates for each id ?
So, try :
SQL> l
1 with tbl as
2 (select 1111 as id, to_date('01/02/2001','DD/MM/YYYY') startdate, to_date('11/03/2001','DD/MM/YYYY') enddate from dual union all
3 select 1111 as id, to_date('02/05/2002','DD/MM/YYYY') startdate, to_date('04/03/2002','DD/MM/YYYY') enddate from dual union all
4 select 1111 as id, to_date('02/06/2000','DD/MM/YYYY') startdate, to_date('02/05/2001','DD/MM/YYYY') enddate from dual union all
5 select 3333 as id, to_date('05/02/2003','DD/MM/YYYY') startdate, to_date('11/03/2003','DD/MM/YYYY') enddate from dual union all
6 select 3333 as id, to_date('06/02/2003','DD/MM/YYYY') startdate, to_date('12/03/2003','DD/MM/YYYY') enddate from dual union all
7 select 3333 as id, to_date('02/06/2005','DD/MM/YYYY') startdate, to_date('02/05/2005','DD/MM/YYYY') enddate from dual )
8 select id, max(decode(dr,1,startdate)) start1,
9 max(decode(dr,1,enddate)) end1,
10 max(decode(dr,2,startdate)) start2,
11 max(decode(dr,2,enddate)) end2,
12 max(decode(dr,3,startdate)) start3,
13 max(decode(dr,3,enddate)) end3
14 from (select id, startdate,enddate, dense_rank() over (partition by id order by startdate) dr from tbl)
15* group by id
SQL> /
ID START1 END1 START2 END2 START3 END3
1111 02/06/00 02/05/01 01/02/01 11/03/01 02/05/02 04/03/02
3333 05/02/03 11/03/03 06/02/03 12/03/03 02/06/05 02/05/05
SQL> HTH,
Nicolas. -
How can I display the rows into columns.
How can I display the rows into columns. I mean
Create table STYLE_M
(Master varchar2(10), child varchar2(10));
Insert itno style_m
('MASTER1','CHILD1');
Insert itno style_m
('MASTER2','CHILD1');
Insert itno style_m
('MASTER2','CHILD2');
Insert itno style_m
('MASTER3','CHILD1');
Insert itno style_m
('MASTER3','CHILD2');
Insert itno style_m
('MASTER3','CHILD3');
Note : The Master may have any number of childs.
I want to display like this..
Master child1, child2, child3, .......(dynamic)
MASTER1 CHILD1
MASTER2 CHILD1 CHILD2
MASTER3 CHILD1 CHILD2 CHILD3
Sorry for disturbing you. Please hlp me out if you have any slution.
Thanks alot.
Ram DontineniHere's a straight SQL "non-dynamic" approach.
This would be used if you knew the amount of children.
SELECT
master,
MAX(DECODE(r, 1, child, NULL)) || ' ' || MAX(DECODE(r, 2, child, NULL)) || ' ' || MAX(DECODE(r, 3, child, NULL)) children
FROM
SELECT
master,
child,
ROW_NUMBER() OVER(PARTITION BY master ORDER BY child) r
FROM
style_m
GROUP BY
master
MASTER CHILDREN
MASTER1 CHILD1
MASTER2 CHILD1 CHILD2
MASTER3 CHILD1 CHILD2 CHILD3 Since you said that the number of children can vary, I incorporated the same logic into a dynamic query.
SET AUTOPRINT ON
VAR x REFCURSOR
DECLARE
v_sql VARCHAR2(1000) := 'SELECT master, ';
v_group_by VARCHAR2(200) := 'FROM (SELECT master, child, ROW_NUMBER() OVER(PARTITION BY master ORDER BY child) r FROM style_m) GROUP BY master';
v_count PLS_INTEGER;
BEGIN
SELECT
MAX(COUNT(*))
INTO v_count
FROM
style_m
GROUP BY
master;
FOR i IN 1..v_count
LOOP
v_sql := v_sql || 'MAX(DECODE(r, ' || i || ', child, NULL))' || ' || '' '' || ';
END LOOP;
v_sql := RTRIM(v_sql, ' || '' '' ||') ||' children ' || v_group_by;
OPEN :x FOR v_sql;
END;
PL/SQL procedure successfully completed.
MASTER CHILDREN
MASTER1 CHILD1
MASTER2 CHILD1 CHILD2
MASTER3 CHILD1 CHILD2 CHILD3I'll point your other thread to this one. -
HELP! SQL Query: Other ways to reorder column display?
I have a SQL query report with a large number of columns (users can hide/show columns as desired). It would be great if the column display order could be changed by changing the order of the columns in the SELECT list in the Report Definition, but that doesn't work -- it puts changed or added columns at the end regardless of the order in the SELECT list of the query.
Is there some other way to reorder the columns displayed without using the Report Attributes page? It's extremely tedious to move columns around using the up/down arrows which redisplays the page each time. Am I missing a way to change display order, or does anyone have a "trick" to do this? It's so painful....
When defining forms you can reoder columns by specifying a sequence number for each column. Just curious as to why reports were not done the same way, and are there any plans to address this in a future release?
KarenYes, reordering columns is extremely painful.
It is supposed to be much improved in the next version.
See
Re: Re-ordering columns on reports
Moving columns up/down in Report Attributes
See my example at
http://htmldb.oracle.com/pls/otn/f?p=24317:141
Basically, let the users move columns around until they are blue in the face, provide a Save button to save the column order in a user preference and reorder the columns when the page reloads.
Or you can use Carl's PL/SQL shuttle as the widget to specify the columns shown and their order. The shuttle is at http://htmldb.oracle.com/pls/otn/f?p=11933:27
Hope this helps.
Message was edited by:
Vikas -
Rows as columns and dynamic alv display
Hi everyone,
I need to build a intenal table dynamically as well as dispaly few rows as columns in alv output.
I have seen posts where internal table has been created dynamicaaly as well seen the posts where rows of the table are displayed as columns but, can we achieve both the functionalities at same time.
I have table as:
SO PO Date MAT QTY
1 A X Y1 10
K1 15
M2 11
2 B X1 Y2 5
M1 12
3 C 1x Z1 15
K1 6
L1 10
Now the ouput has to be :
SO PO Date MAT-Y1 MAT-K1 MAT-Y2 MAT-L1 Mat-Z1 MAT-M1 MAT-M2
1 A X 10 15 11
2 B X1 5 12
3 C 1X 6 10 15
I will not be knowing the number of materials untill runtime(dynamic) and as well the rows has to be displayed as columns. Is it possible to do that.
Regards
Edited by: Madhu Posanipalli on Jun 6, 2011 4:51 PMHi,
Check below code. It will work definitly.
*& Report YTEST_PROG_RP
REPORT YTEST_PROG_RP.
type-POOLs slis.
TYPES: BEGIN OF ty_tab,
so TYPE i,
po TYPE c,
date(2) TYPE c,
mat(2) TYPE c,
qty TYPE i,
END OF ty_tab.
DATA: itab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
jtab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
ktab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,
wa_tab TYPE ty_tab, wa_j TYPE ty_tab, wa_k TYPE ty_tab.
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> type any.
*ALV data declarations
data: fieldcatalog type LVC_T_FCAT, " with header line, "slis_t_fieldcat_alv with header line,
fieldcatalog1 TYPE LVC_s_FCAT,
fieldcatalog2 type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
DATA t_newtable TYPE REF TO data.
DATA t_newline TYPE REF TO data.
DATA wa_flname TYPE string.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform dynamic_table.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
form build_fieldcatalog.
DATA: lv_field1 TYPE string, lv_cnt LIKE sy-tabix VALUE 3, itab_lines TYPE i.
DATA: fieldname(20) TYPE c.
DATA: fieldvalue(10) TYPE c.
DATA: index(3) TYPE c.
DATA: wa_cat LIKE LINE OF fieldcatalog2,
wa_colno(2) TYPE n,
wa_flname(5) TYPE c. .
fieldcatalog1-fieldname = 'SO'.
fieldcatalog1-seltext = 'SO'.
fieldcatalog1-col_pos = 1.
fieldcatalog1-outputlen = 2.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog1 to fieldcatalog.
clear fieldcatalog1.
fieldcatalog1-fieldname = 'PO'.
fieldcatalog1-seltext = 'PO'.
fieldcatalog1-col_pos = 2.
fieldcatalog1-outputlen = 2.
append fieldcatalog1 to fieldcatalog.
clear fieldcatalog1.
fieldcatalog1-fieldname = 'DATE'.
fieldcatalog1-seltext = 'Date'.
fieldcatalog1-col_pos = 3.
fieldcatalog1-outputlen = 2.
append fieldcatalog1 to fieldcatalog.
clear fieldcatalog1.
LOOP AT itab INTO wa_tab.
lv_cnt = lv_cnt + 1.
CONCATENATE 'MAT-' wa_tab-mat into lv_field1.
TRANSLATE lv_field1 TO UPPER CASE.
fieldcatalog1-fieldname = lv_field1.
fieldcatalog1-seltext = lv_field1.
fieldcatalog1-col_pos = lv_cnt.
fieldcatalog1-outputlen = 6.
append fieldcatalog1 to fieldcatalog.
clear fieldcatalog1.
CLEAR: lv_field1, wa_tab.
ENDLOOP.
CLEAR lv_cnt.
Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fieldcatalog
IMPORTING
ep_table = t_newtable.
ASSIGN t_newtable->* TO <t_dyntable>.
CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
ASSIGN t_newline->* TO <fs_dyntable>.
DESCRIBE TABLE fieldcatalog LINES itab_lines.
loop at fieldcatalog INTO fieldcatalog1.
CLEAR wa_cat.
wa_cat-fieldname = fieldcatalog1-fieldname.
wa_cat-seltext_s = fieldcatalog1-fieldname.
wa_cat-outputlen = fieldcatalog1-outputlen.
APPEND wa_cat TO fieldcatalog2.
CLEAR fieldcatalog1.
ENDLOOP.
endform. " BUILD_FIELDCATALOG
*& Form BUILD_LAYOUT
Build layout for ALV grid report
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
Display report using ALV grid
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog2[]
it_special_groups = gd_tabgroup
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
is_variant = z_template
tables
t_outtab = <t_dyntable>
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
form data_retrieval.
DATA: lv_index LIKE sy-tabix.
wa_tab-so = 1.
wa_tab-po = 'A'.
wa_tab-date = 'X'.
wa_tab-mat = 'Y1'.
wa_tab-qty = 10.
append wa_tab to itab.
clear wa_tab.
wa_tab-mat = 'K1'.
wa_tab-qty = 15.
append wa_tab to itab.
CLEAR wa_tab.
wa_tab-mat = 'M2'.
wa_tab-qty = 11.
append wa_tab to itab.
CLEAR wa_tab.
wa_tab-so = 2.
wa_tab-po = 'B'.
wa_tab-date = 'X1'.
wa_tab-mat = 'Y2'.
wa_tab-qty = 5.
append wa_tab to itab.
CLEAR wa_tab.
wa_tab-mat = 'M1'.
wa_tab-qty = 12.
append wa_tab to itab.
CLEAR wa_tab.
wa_tab-so = 3.
wa_tab-po = 'C'.
wa_tab-date = '1x1'.
wa_tab-mat = 'Z1'.
wa_tab-qty = 15.
append wa_tab to itab.
CLEAR wa_tab.
wa_tab-mat = 'K1'.
wa_tab-qty = 6.
append wa_tab to itab.
CLEAR wa_tab.
wa_tab-mat = 'L1'.
wa_tab-qty = 10.
append wa_tab to itab.
CLEAR wa_tab.
LOOP AT itab INTO wa_tab.
if wa_tab-so is NOT INITIAL AND wa_tab-po is NOT INITIAL AND wa_tab-date is NOT INITIAL.
wa_j-so = wa_tab-so.
wa_j-po = wa_tab-po.
wa_j-date = wa_tab-date.
lv_index = wa_tab-so.
else.
READ TABLE itab INTO wa_j WITH KEY so = lv_index.
ENDIF.
wa_j-mat = wa_tab-mat.
wa_j-qty = wa_tab-qty.
APPEND wa_j to jtab.
CLEAR: wa_tab, wa_j.
ENDLOOP.
endform. " DATA_RETRIEVAL
Form TOP-OF-PAGE *
ALV Report Header *
Form top-of-page.
**ALV Header declarations
*data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
i_logo = 'Z_LOGO'.
endform. "top-of-page
FORM USER_COMMAND *
--> R_UCOMM *
--> RS_SELFIELD *
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
Check function code
CASE r_ucomm.
WHEN '&IC1'.
Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'EBELN'.
Read data table, using index of row user clicked on
READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
Set parameter ID for transaction screen field
SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
Sxecute transaction ME23N, and skip initial data entry screen
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM. "user_command
*& Form BUILD_EVENTS
Build events table
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*& Form BUILD_PRINT_PARAMS
Setup print parameters
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*& Form END_OF_PAGE
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform. "END_OF_PAGE
*& Form END_OF_LIST
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform. "END_OF_LIST
*& Form dynamic_table
text
--> p1 text
<-- p2 text
FORM dynamic_table .
DATA: lv_s1 TYPE string, lv_s2 TYPE string.
DATA lv_mat TYPE string.
DATA: fieldvalue(10) TYPE c.
ktab[] = jtab[].
delete ADJACENT DUPLICATES FROM ktab COMPARING so.
loop at ktab INTO wa_tab.
Field1
wa_flname = 'SO'.
fieldvalue = wa_tab-so.
CONDENSE fieldvalue NO-GAPS.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
CLEAR fieldvalue.
Field2
wa_flname = 'PO'.
fieldvalue = wa_tab-po.
CONDENSE fieldvalue NO-GAPS.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
CLEAR fieldvalue.
Field3
wa_flname = 'DATE'.
fieldvalue = wa_tab-date.
CONDENSE fieldvalue NO-GAPS.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
CLEAR fieldvalue.
loop at jtab INTO wa_j WHERE so = wa_tab-so.
CONCATENATE 'MAT-' wa_j-mat INTO lv_mat.
wa_flname = lv_mat.
fieldvalue = wa_j-qty.
CONDENSE fieldvalue NO-GAPS.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
CLEAR: wa_j, fieldvalue.
ENDLOOP.
APPEND <fs_dyntable> TO <t_dyntable>.
CLEAR wa_tab.
FREE <fs_dyntable>.
ENDLOOP.
ENDFORM. " dynamic_table
Ram. -
How to display number of rows as columns in a select statement? This is on
How to display number of rows as columns in a select statement? This is on 10g R2.
Thanks,
RFor the current (ie. row 1 of 100)
row_number over (order by -pick_a_column_set) as rnfor the total number of columns returned in your query
count(*) over() as total_count -
How to display Rows as Columns in JSF?
I am using dataTable component to get data for my Menu, i have one column in it which returns me the data, because its automatically adding <tr> and <td> tags to it, its showing data in tabular form.
I want to show output Horizontally instead of Vertically the way its showing.
Is their any way i can display Rows as Columns?
Code:
==============================================
<div class="bodyarea">
<div id="location">
<h:dataTable value="#{menuItem.breadCrumb}" var="bread" >
<f:verbatim><ol></f:verbatim>
<h:column>
<f:verbatim><li></f:verbatim>
<h:outputLink id="crumbID" value="#{bread.menuLink}">
<h:outputText id="crumpName" value="#{bread.menuLabel}"/>
</h:outputLink>
<f:verbatim></li></f:verbatim>
</h:column>
<f:verbatim></ol></f:verbatim>
</h:dataTable>
</div>
</div>
Thank youTable is not the html element for you, in this situation.
I would use a dataList component (distributed with myfaces implementation).
dataList is able to return a list of item, and using css you will be able display in a horizontal grid. (otherwise you can use layout="grid" in dataList).
Anyway...my impression is that who made JSF was not really understanding how a html programmer like to write his code.
Why do JSF gives us only the possibility to write list of items throught tables?
Why do JSF prints error messages throught tables?
Why div is not a standard component?
This is an incredible lack...
I see also other incredible lasks...but they don't concern html ;) . -
Referring to Cursor Row and Column in Dynamic SQL
I have a procedure that dynamically reads a schema name and table name from an input table. The code then needs to loop through all rows and columns of each table and output the data. I'm 95% done with what I want to accomplish, but there is one small bug. The line dbms_output.put(*col.column_name* || '',''); ' ||
should refer to something like rec.col.column_name so that it gets the column of the current record. Right now it just displays the column name for each record instead of the actual value. Can anyone help me tweak the code to get the actual value?
CREATE OR REPLACE PACKAGE BODY some_proc IS
-- Function and procedure implementations
PROCEDURE create_files IS
CURSOR c_tbls IS
SELECT * FROM tbl_list;
l_sql VARCHAR2(4000);
BEGIN
--Loop through all tables
FOR tbl IN c_tbls LOOP
l_sql := 'DECLARE ' || ' CURSOR c_tbl_recs IS ' || ' SELECT * ' ||
' FROM ' || tbl.schema_name || '.' || tbl.table_name || '; ' ||
' t_tbl_rowtype c_tbl_recs%ROWTYPE; ' || 'BEGIN ' ||
' FOR rec IN c_tbl_recs LOOP ' ||
' FOR col IN (SELECT column_name ' ||
' FROM dba_tab_cols ' ||
' WHERE owner = ''' || tbl.schema_name || '''' ||
' AND table_name = ''' || tbl.table_name || '''' ||
' ORDER BY column_id) LOOP ' ||
*' dbms_output.put(col.column_name || '',''); ' ||* ' END LOOP; dbms_output.put_line(''''); END LOOP; ' ||
'END; ';
--dbms_output.put_line(l_sql);
EXECUTE IMMEDIATE l_sql;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SQLERRM);
END;
END;Is it this what you are looking for?
(it took some minutes)
create or replace
package some_proc is
procedure create_files;
end;
CREATE OR REPLACE
PACKAGE BODY some_proc
IS
-- Function and procedure implementations
PROCEDURE create_files
IS
CURSOR c_tbls
IS
SELECT * FROM tbl_list;
CURSOR c_cols (p_table_owner VARCHAR2, p_table_name VARCHAR2)
IS
SELECT column_name
FROM all_tab_columns
WHERE owner =p_table_owner
AND table_name=p_table_name
ORDER BY all_tab_columns.column_id;
l_sql VARCHAR2(32000);
separator VARCHAR2(1):=';';
BEGIN
--Loop through all tables
FOR tbl IN c_tbls
LOOP
dbms_output.put_line('TABLE: '||tbl.schema_name||'.'||tbl.table_name);
l_sql := 'DECLARE ' ;
l_sql := l_sql|| ' CURSOR c_tbl_recs IS ' ;
l_sql := l_sql||' SELECT * FROM ' || tbl.schema_name || '.' || tbl.table_name || '; ' ;
l_sql := l_sql||' linenr number:=1; ';
l_sql := l_sql||'BEGIN ' ;
l_sql := l_sql|| ' FOR rec IN c_tbl_recs LOOP ';
FOR c IN c_cols(tbl.schema_name,tbl.table_name)
LOOP
l_sql:=l_sql ||' if linenr=1 then dbms_output.put('''||c.column_name||''||separator||'''); end if; ' ;
END LOOP;
l_sql :=l_sql||' dbms_output.put_line(''''); linenr:=linenr+1; ';
FOR c IN c_cols(tbl.schema_name,tbl.table_name)
LOOP
l_sql:=l_sql ||' dbms_output.put(rec.'||c.column_name||'||'''||separator||'''); ' ;
END LOOP;
l_sql:=l_sql||' end loop; ';
l_sql:=l_sql||' dbms_output.put_line(''''); ';
l_sql:=l_sql||' dbms_output.put_line(''''); ';
l_sql:=l_sql||'end;';
EXECUTE IMMEDIATE l_sql;
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SQLERRM);
END;
END;
/ -
Rows to be displayed as columns
DB : 10.2.0.4.0
Os : solaris 5.10
I have a table with the below rows and columns
EARNINGS EARNINGS_VALUE
Allowance 97.28
Salary 3,404.80
Allowance_1 875.52
Allowance_2 194.56
Allowance_3 291.84
{code}
I want to display this as follows :
{code}
Allowance Salary Allowance_1 Allowance_2 Allowance_3
97.28 3,404.80 875.52 194.56 291.84
{code}
Please suggest
KaiHello, try:
WITH your_table AS (SELECT 'Allowance' EARNINGS, 97.28 EARNINGS_VALUE FROM DUAL UNION ALL
SELECT 'Salary', 3404.80 FROM DUAL UNION ALL
SELECT 'Allowance_1', 875.52 FROM DUAL UNION ALL
SELECT 'Allowance_2', 194.56 FROM DUAL UNION ALL
SELECT 'Allowance_3', 291.84 FROM DUAL)
-- end test data
SELECT Allowance, Salary, Allowance_1, Allowance_2, Allowance_3
FROM (
SELECT MAX(CASE EARNINGS WHEN 'Allowance' THEN EARNINGS_VALUE ELSE NULL END) Allowance,
MAX(CASE EARNINGS WHEN 'Salary' THEN EARNINGS_VALUE ELSE NULL END) Salary,
MAX(CASE EARNINGS WHEN 'Allowance_1' THEN EARNINGS_VALUE ELSE NULL END) Allowance_1,
MAX(CASE EARNINGS WHEN 'Allowance_2' THEN EARNINGS_VALUE ELSE NULL END) Allowance_2,
MAX(CASE EARNINGS WHEN 'Allowance_3' THEN EARNINGS_VALUE ELSE NULL END) Allowance_3
FROM your_table
ALLOWANCE SALARY ALLOWANCE_1 ALLOWANCE_2 ALLOWANCE_3
97.28 3404.8 875.52 194.56 291.84
Maybe you are looking for
-
How do I get my Kodak ESP 3.2s printer to print documents from my iPad ?
I have an iPad I have a Kodak ESP 3.2s all in one printer I have set it up to print via my home wi fi using my normal laptop with Microsoft However I couldn't work out how to print from my iPad as its not configured for Apple! I downloaded Kodak Pic
-
Getting an Error in Deploying JMS and Message Driven Beans
HI , When I m trying to deploy my application It is giving the following exception cn any one plz help .. I think m not writing correct XML so can any one plz give me any help regarding How to write XML.. 0,333 ERROR [JMSContainerInvoker] Could not s
-
Restrictions passcode for iPhone 4. I need to erase all content and settings for handset
-
Hi all, I am have a requirement in smartform. I have to Display the Graph as my output. If any one worked on this please help me out. Thanks in advance. Ranjit
-
Music files not found by music app
Hi, I tried putting some music on my Q10, but the music app does not find it, or rather only finds some of the files. The weird thing is that I've deleted and copied the music several times now, and the files recognised aren't the same. Any idea what