Rows to column output
oracle 10.2.0.4
os : Linux
I am running a sql
Select ISSUE_CAT, to_char(issue_dt,'IW') as week_no, count(*) tasks from osdba_works where issue_class ='CC' and issue_dt between '01-mar-2009' and '31-mar-2009'
group by ISSUE_CAT,to_char(issue_dt,'IW')
order by 1
which is giving output as below
38 09 2
38 13 1
39 12 3
40 11 5
40 12 2
40 13 2
40 14 1
41 11 1
41 13 2
42 12 1
46 11 1
IS WE TASKS
46 13 1
I want output as
Cat 9 10 11 12 13 14 tot
38 2 1 3
39 3 3
40 5 2 2 1 10
41 1 2 3
42 1 1
46 1 1
tot 2 0 7 6 5 1 21 Can we write sql for this kind? do we need to use a reporting tool for this.
If possible pl. inform. even without total it is ok
I have edited the output
Edited by: [email protected] on Mar 31, 2009 1:58 PM
And also ROLLUP
--SAMPLE DATA START--
with t
as
select 38 c1, 09 c2, 2 c3 from dual union all
select 38, 13, 1 from dual union all
select 39, 12, 3 from dual union all
select 40, 11, 5 from dual union all
select 40, 12, 2 from dual union all
select 40, 13, 2 from dual union all
select 40, 14, 1 from dual union all
select 41, 11, 1 from dual union all
select 41, 13, 2 from dual union all
select 42, 12, 1 from dual union all
select 46, 11, 1 from dual
--SAMPLE DATA END--
t1
as
select decode(grouping(C1),1,'Total',c1) c1,
sum(nvl(decode(c2,09,c3),0)) "09",
sum(nvl(decode(c2,10,c3),0)) "10",
sum(nvl(decode(c2,11,c3),0)) "11",
sum(nvl(decode(c2,12,c3),0)) "12",
sum(nvl(decode(c2,13,c3),0)) "13",
sum(nvl(decode(c2,14,c3),0)) "14"
from t
group by rollup(c1)
order by c1
select c1, "09","10","11","12","13","14", "09"+"10"+"11"+"12"+"13"+"14" total
from t1
Similar Messages
-
Retrieve multiple row single column output as single string
hii
I have query like "select country_name from country_master where <condition>".
This query results in multiple rows. I want those multiple rows as a string like "country1, country2, contry3".
I know i can write a function/cursor to achieve that but want to know if we have a way to get that within the query itself.
ThanksIn 10g...
SQL> select dname from dept;
DNAME
ACCOUNTING
RESEARCH
SALES
OPERATIONS
IT SUPPORT
SQL> ed
Wrote file afiedt.buf
1 select ltrim(sys_connect_by_path(dname,','),',') as depts
2 from (select dname, row_number() over (order by deptno) rn from dept)
3 where connect_by_isleaf = 1
4 connect by rn = prior rn + 1
5* start with rn = 1
SQL> /
DEPTS
ACCOUNTING,RESEARCH,SALES,OPERATIONS,IT SUPPORTIn 11g, you can use the LISTAGG analytical function. -
Table name input. and output i need all rows and columns using procedures
hi,
question: table name input. and output i need all rows and columns by using procedures.
thanks,
To AllAn example of using DBMS_SQL package to execute dynamic SQL (in this case to generate CSV data in a file)...
As sys user:
CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
/As myuser:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
,p_dir IN VARCHAR2
,p_header_file IN VARCHAR2
,p_data_file IN VARCHAR2 := NULL) IS
v_finaltxt VARCHAR2(4000);
v_v_val VARCHAR2(4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
v_fh UTL_FILE.FILE_TYPE;
v_samefile BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
BEGIN
c := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
END CASE;
END LOOP;
-- This part outputs the HEADER
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
FOR j in 1..col_cnt
LOOP
v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
IF NOT v_samefile THEN
UTL_FILE.FCLOSE(v_fh);
END IF;
-- This part outputs the DATA
IF NOT v_samefile THEN
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
END IF;
LOOP
v_ret := DBMS_SQL.FETCH_ROWS(c);
EXIT WHEN v_ret = 0;
v_finaltxt := NULL;
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
ELSE
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
END CASE;
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
END LOOP;
UTL_FILE.FCLOSE(v_fh);
DBMS_SQL.CLOSE_CURSOR(c);
END;This allows for the header row and the data to be written to seperate files if required.
e.g.
SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
PL/SQL procedure successfully completed.Output.txt file contains:
empno,ename,job,mgr,hiredate,sal,comm,deptno
7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
Adapt to output different datatypes and styles are required. -
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. -
When I was Importing data from XML to SqlServer using SSIS , I am getting this error. The import is working if i use small file and not working if I use large XMl file. Can any one of you guys help me out with the issue?
Error: 0xC020902A at Data Flow Task, XML Source [24515]: The "component "XML Source" (24515)" failed because truncation occurred, and the truncation row disposition on "output column "MsgLev1" (26196)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
Error: 0xC02092AF at Data Flow Task, XML Source [24515]: The component "XML Source" (24515) was unable to process the XML data. Pipeline component has returned HRESULT error code 0xC020902A from a method call.
Error: 0xC0047038 at Data Flow Task: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "XML Source" (24515) returned error code 0xC02092AF. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.
Error: 0xC0047021 at Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "SourceThread0" has exited with error code 0xC0047038. There may be error messages posted before this with more information on why the thread has exited.
Error: 0xC0047039 at Data Flow Task: SSIS Error Code DTS_E_THREADCANCELLED. Thread "WorkThread0" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown. There may be error messages posted before this with more information on why the thread was cancelled.
Error: 0xC0047039 at Data Flow Task: SSIS Error Code DTS_E_THREADCANCELLED. Thread "WorkThread1" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown. There may be error messages posted before this with more information on why the thread was cancelled.
Error: 0xC0047039 at Data Flow Task: SSIS Error Code DTS_E_THREADCANCELLED. Thread "WorkThread3" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown. There may be error messages posted before this with more information on why the thread was cancelled.
Error: 0xC0047039 at Data Flow Task: SSIS Error Code DTS_E_THREADCANCELLED. Thread "WorkThread4" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown. There may be error messages posted before this with more information on why the thread was cancelled.
Error: 0xC0047039 at Data Flow Task: SSIS Error Code DTS_E_THREADCANCELLED. Thread "WorkThread2" received a shutdown signal and is terminating. The user requested a shutdown, or an error in another thread is causing the pipeline to shutdown. There may be error messages posted before this with more information on why the thread was cancelled.
Error: 0xC0047021 at Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread0" has exited with error code 0xC0047039. There may be error messages posted before this with more information on why the thread has exited.
Error: 0xC0047021 at Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread1" has exited with error code 0xC0047039. There may be error messages posted before this with more information on why the thread has exited.
Error: 0xC0047021 at Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread2" has exited with error code 0xC0047039. There may be error messages posted before this with more information on why the thread has exited.
Error: 0xC0047021 at Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread3" has exited with error code 0xC0047039. There may be error messages posted before this with more information on why the thread has exited.
Error: 0xC0047021 at Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread4" has exited with error code 0xC0047039. There may be error messages posted before this with more information on why the thread has exited.The reason is in the first line of the error. It doesn't have anything to do with the size of your XML file - it has to do with the contents of the "MsgLev1" column. You (or the XSD) has indicated that the values in this column not exceed a certain size - but one of the values in the file that's failing is larger than that.
In order to fix the problem, you're going to need to increase the allocated space for that column. In order to do that, you're going to need to find out what the required size of that data is - either from someone who ought to know, or by direct examination of the file. If you want to know which entity has this overly large data element in it, you need to configure the error handling of the XML Source to "redirect truncation errors". Then you can hook up the XML Source's error output to another destination where you can see which rows are problematic.
Talk to me on -
How to add a comment for each row on the output of a report?
I would like to add a comment (field) for each row on the output of report? This comment should to be saved as well. Is there a way i can do that?
Regards,
RamHi Dimitri,
through the instead of trigger functionality i am able to update the view. This is view is based on different views which should be linked to a table (as you suggested) in which comments can be stored. Hower this table is empty and how to link this table with the view now? I face the following challenge.
View consists the following columns, for example
select name, sex, age from test_view
name sex age
John M 20
Anton M 30
Willy M 40
shirley F 38
sharon F 37
The report has the following output, for example
name sex age
John M 20
Anton M 30
Willy M 40
Shirley F 38
Sharon F 37
Now i would like to add comment through a button.
The report layout looks like
name sex age
John M 20 <add comment button>
After submitting the <add comment button> you can enter text which deals with John
text='John doesnot like me'
Finally the report display the comment as well
name sex age
John M 20 'John doesnot like me' <update/delete comment button>
Anton M 30 <add comment button>
Willy M 40 <add comment button>
Shirley F 38 <add comment button>
Sharon F 37 <add comment button>
After submitting the <update/delete button> you can change or delete the entered text.
I hope this example clears things up.
Regards,
Ram -
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. -
Hello All,
I have a requirement where I have to convert rows to columns and vice versa in 10g.
Pivot isn't supported in 10g.
Actual query looks like this
change_name primary_key_id
ASSET 1501
COLLATERAL 1501
ASSET 1502
COLLATERAL 1510
ASSET 1503
COLLATERAL 1515
Required Output:
change_table_name Asset Collateral
Primary_key_id 1501 1501
Primary_key_id2 1502
Primary_key_id3 1510
Primary_key_id4 1503
Primary_key_id5 1515Thx
Shank.
Edited by: SamFisher on May 16, 2012 7:48 PMHi,
SamFisher wrote:
Hello All,
I have a requirement where I have to convert rows to columns and vice versa in 10g.
Pivot isn't supported in 10g.Pivot can be done in any version of Oracle.
The PIVOT keyword of the SELECT command isn't supported in Oracle 10. That's only one way of pivoting.
Actual query looks like this
change_name primary_key_id
ASSET 1501
COLLATERAL 1501
ASSET 1502
COLLATERAL 1510
ASSET 1503
COLLATERAL 1515
Required Output:
change_table_name Asset Collateral
Primary_key_id 1501 1501
Primary_key_id2 1502
Primary_key_id3 1510
Primary_key_id4 1503
Primary_key_id5 1515
I think you want something like this:
SELECT 'Primary_key_id
|| TO_CHAR ( NULLIF ( ROW_NUMBER () OVER (ORDER BY NVL ( a.primary_key_id
, c.primary_key_id
, 1
) AS change_table_name
, a.primary_key_id AS asset
, c.primary_key_id AS collateral
FROM table_x a
FULL OUTER JOIN table_x c ON a.primary_key_id = c.primary_key_id
-- Next 4 lines added after Ankit, below
AND a.change_name = 'ASSET'
AND c.change_name = 'COLLATERAL'
WHERE a.change_name = 'ASSET'
OR c.change_name = 'COLLATERAL'
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.
This generates a unique change_table_name for each row. I don't see how you get the values you said you wanted associated with the other columns. That is, I have the same question as Justin:
Justin Cave wrote:
... How do you know that 1502 goes with primary_key_id2 and not primary_key_id3 or 4 or 1?Perhaps you don't really care which change_table_name is given to each row, just so long as they are unique, and numbered with consecutive integers (except for 1). If you really do need exactly what you posted, explain how you get it. You probably just need to change the analytic ORDER BY clause.
Edited by: Frank Kulash on May 17, 2012 6:56 AM
Corrected query -
How can I find out the first intial row in VA02-output transaction??
How can I find out the first intial row in the screen which appears during sales order change (VA02) >>enter the sales order number >>after the first screen appears >>in the menu bar go to EXTRAS>>OUTPUT>>HEADER>>EDIT??
I have to find out the first row in the OUTPUT column which is empty,then populate it with some data using BDC.
usefull answers will be rewarded.
regards,
Shashank .Pass the sale order number in the object key of NAST table,
if u get 3 entires, then u need to place ur entry in the fourth row in that table control thru BDC.
I think u got the logic.
Regards,
Sujatha. -
Rows to column and need to nvl for that newly columns
Hi,
I have to create rows to column query in rdf and in turn i have to created excel rtf template to produce excel output.
select max(decode (test.role, 'PA-ELT Member', test.full_name )) ELT_MEMBER,
max(decode (test.role, 'PA-IT Director', test.full_name )) IT_MEMBER,
max(decode (test.role, 'Project Manager', test.full_name )) Project_Manager,
TEST.segment1 project_NUMber,
test.name project_Name,
test.project_id,
test.project_type ,
test.organization_name,
TEST.project_status_name Status_Name,
TEST.start_date Start_date,
TEST.COMPLETION_DATE,
TEST.Planned_OOE,
TEST.Planned_Dep,
TEST.Planned_lab
from
(select
pppv.full_name,
pppv.role,
ppa.name,
ppa.project_id,
ppa.segment1,
ppa.project_type,
(select name from PA_ALL_ORG_V where organization_id = ppa.CARRYING_OUT_ORGANIZATION_ID) organization_name,
ppa.PROJECT_STATUS_CODE,
pps.PROJECT_STATUS_NAME,
ppa.START_DATE,
ppa.COMPLETION_DATE,
(select N_EXT_ATTR1 from PA_PROJECTS_ERP_EXT_B where project_id = ppa.project_id and ATTR_GROUP_ID = 243) Planned_OOE,
(select N_EXT_ATTR2 from PA_PROJECTS_ERP_EXT_B where project_id = ppa.project_id and ATTR_GROUP_ID = 243) Planned_Dep,
(select N_EXT_ATTR3 from PA_PROJECTS_ERP_EXT_B where project_id = ppa.project_id and ATTR_GROUP_ID = 243) Planned_lab
from
PA_PROJECTS_ALL ppa, PA_PROJECT_PLAYERS_V pppv, pa_project_statuses pps
where ppa.project_id = pppv.project_id
and ppa.PROJECT_STATUS_CODE = pps.PROJECT_STATUS_CODE
and pppv.role in ('PA-ELT Member','PA-IT Director','Project Manager')
and ppa.CARRYING_OUT_ORGANIZATION_ID=3994
)test
where 1=1
and TEST.project_type = nvl(:P_PROJECT_TYPE,test.project_type)
and TEST.project_status_name = nvl(:P_PROJECT_STATUS,test.project_status_name)
and TEST.segment1 = nvl(:P_PROJECT_NUMBER,test.segment1)
and TEST.full_name = nvl(:P_ELT_MEMBER, test.full_name)
and test.full_name = nvl(:P_IT_DIRECTOR,test.full_name)
and TEST.full_name = nvl(:P_PROJECT_MANAGER,test.full_name)
group by
TEST.segment1,
test.name,
test.project_id,
test.project_type,
test.organization_name,
TEST.project_status_name,
TEST.start_date,
TEST.COMPLETION_DATE,
TEST.Planned_OOE,
TEST.Planned_Dep,
TEST.Planned_lab
order by TEST.SEGMENT1
see ELT_MEMBER,IT_MEMBER and Project_Manager are columns created from rows to column.
now if i put where clause for this any columns for Eg: ELT_MEMBER it is giving Elt_member column values alone not remaining IT_member and Project Manager it show null even it has values .
it is because of this where clause
and TEST.full_name = nvl(:P_ELT_MEMBER, test.full_name)
and test.full_name = nvl(:P_IT_DIRECTOR,test.full_name)
and TEST.full_name = nvl(:P_PROJECT_MANAGER,test.full_name)
though i have ELT_MEMBER, IT_member and Project Manager column in where clause i have to call parent sql query column full_name.
i have tried to have nvl on column like below.
nvl( max(decode (test.role, 'Project Manager', test.full_name )),(select full_name from PA_PROJECT_PLAYERS_V where project_id = test.project_id and role ='Project Manager')) Project_Manager,
but it is showing error single -row subquery error .
it is possible to have a where clause for rows to columns .
Please help in this regardsSQL> ed
Wrote file afiedt.buf
1 with t as (select 'john,henry,michi,glen' as customer_name, 25000 as credit_limit from dual union all
2 select 'dilon,bryan', 10000 from dual union all
3 select 'raymond', 8000 from dual)
4 -- END OF TEST DATA
5 select regexp_substr(customer_name, '[^,]+', 1, rn) as customer_name, credit_limit
6 from t
7 ,(select rownum rn
8 from dual
9 connect by rownum <= (select max(length(regexp_replace(t.customer_name,'[^,]'))+1) from t))
10 where regexp_substr(customer_name, '[^,]+', 1, rn) is not null
11* order by credit_limit desc
SQL> /
CUSTOMER_NAME CREDIT_LIMIT
john 25000
henry 25000
michi 25000
glen 25000
bryan 10000
dilon 10000
raymond 8000
7 rows selected.
SQL>Just replace "t" with your query to select the data from the external table. -
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 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 ;) . -
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 3Three 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 -
Dynamic query, row to column
Hi.
Is any way to select one row as column for any table exists?
I mean some script which have table name and condition as input parameters, and prints column_name || column value;
I have tried to do it, but have some problems.
e.g. have table
create table my_table (column1 number, column2 number, column3 number);
insert into my_table values (1,2,3);It should be something like:
declare
lv_table_name varchar2(40):='MY_TABLE'; /*these are input paremeters*/
lv_condition varchar2(300):='column1=1;/*these are input paremeters*/
begin
/*body*/
end;and output should be like (may use dbms_output)
column1 1
column2 2
column3 3 Script should work for any table.
Does anybody solves task similar to this?http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1035431863958
Search for procedure print_table on that page. -
Converting rows to columns using dynamic query.
I am trying to use the below code that I founnd on the web to conver rows to columns. the reason that I want to use dynamic query is that the number of rows are not know and changes.
declare
lv_sql varchar2(32767) := null ;
begin
lv_sql := 'SELECT Iplineno ';
for lv_rec in (SELECT distinct vendor from bidtabs where letting = '10021200' and call ='021')
loop
lv_sql := lv_sql
|| CHR(10)
|| ', MAX( DECODE( vendor, '
|| chr(39)
|| lv_rec.vendor
|| CHR(39)
|| ', bidprice, NULL ) ) as "'
|| lv_rec.vendor
|| '" ' ;
end loop;
lv_sql := lv_sql
|| CHR(10)
|| 'FROM bidtabs where letting = ''10021200'' and call = ''021'' and lineflag = ''L'' '
|| CHR(10)
|| 'GROUP BY iplineno ;' ;
here is the result
BIDPRICE CALL IPLINENO LETTING VENDOR
9,585 021 0010 10021200 C0104
1,000 021 0020 10021200 C0104
1,000 021 0030 10021200 C0104
17 021 0040 10021200 C0104
5 021 0050 10021200 C0104
11,420 021 0010 10021200 K0054
1,100 021 0020 10021200 K0054
1,100 021 0030 10021200 K0054
5 021 0040 10021200 K0054
3 021 0050 10021200 K0054
8,010 021 0010 10021200 V070
900 021 0020 10021200 V070
1,320 021 0030 10021200 V070
11 021 0040 10021200 V070
3 021 0050 10021200 V070
and here is the desired output
CALL IPLINENO LETTING C0104 K0054 V070
021 0010 10021200 9,585 11,420 8,010
021 0020 10021200 1,000 1,100 900
021 0030 10021200 1,000 1,100 1,320
021 0040 10021200 17 5 11
021 0050 10021200 5 3 3Here is the error message I am getting:
RA-06550: line 22, column 43:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
pipe
Maybe you are looking for
-
Need toughts on approach. Client moving to Maconomy/Business Objects
Post Author: klokhammer CA Forum: General Feedback Hi.On of our important clients are most likely to migrate between economy systems within the next 9 months. Case as follows: We have developed a budgeting/forecast and reporting system for a certain
-
How can I get an apple id for an other country
I am studying in the Netherlands and now I need to have a Dutch app but Originally I am logged in with my German Apple ID. Now I just started from the beginnig and made a new account for the Dutch App Store but as soon as try to log in on my iPhone I
-
Error while uploading data in SAP (me01)using LSMW
Hi All, I am using LSMW for the first time. I am trying to upload data to the Source List transaction (me01) using batch input recording. I created a new recording through LSMW itself. My source structure consists of 5 fields: <b>MATNR C(18) WERKS C(
-
Installation Error: "install" can't be opened-"
After spending 4 hours downloaded CS Design Premium 5.5. From here: http://prodesigntools.com/adobe-cs5-5-direct-download-links.html Double click and hope to begin when I get the following error, ' "install can't be opened because it is from an unide
-
Problem with internal table initialisation in EBP system
Hi I work in EBP system, and i made a specific work in LBBP_POCF0o program. It is in the displaying items of a purchase order. This is what i done: LOOP AT t_screen_items WHERE del_ind NE 'X'. w_old_total = w_old_total + t_screen_items-value.