Display data in single row
i have table dept of deptno d001,d002,d003,d004
i want to list the data like below
deptno
d001,d002,d003,d004 ( in a single row)
is it possible..?
S
Based on your database version you can try any one of the following http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
Similar Messages
-
Spry:repeat display data in multiple rows/columns
I know how to use spry:repeat to display data in table rows,
one item per row.
Is there a way to tell spry to display data in a grid of x
rows by y columns?
I'm trying to maximize the page's real estate. Here is the
page
http://www.jannah.com/mp3/browse.html
Click on "Artist/Scholar" in "STEP1" section. "STEP2" section
gets filled with a list. I'm trying to display that list in 3
columns and as many rows as needed. How do I do that?
While I'm at it, I also can't figure out why the spry:select
is not working for "STEP2" section; I need to click twice on the
same item to get it highlighted. the other spry selects on the page
work ok. Can someone take a look.
Greatly appreciated.You can't use Spry with tables to do this, but if you're up
to using a div based layout/presentation, it is possible. Check out
the Zuggest sample:
http://labs.adobe.com/technologies/spry/samples/data_region/ZuggestSample.html
It uses floated divs to get the same effect. The nice thing
about using divs, is that more columns dynamically appear as the
horizontal real-estate is expanded.
--== Kin ==-- -
Displaying data in one row for for 2 tables without relaiton
I Have 2 tables without any relation and there is a common field and i want to display data like below
table refdet
1)
refdt----------refbr----refamt----refcat
10-aug-09---10-----34234-----101a
10-aug-009--11----23245-----102a
1-AUG-09----10----455.98----104A
19-aug-09-12-----10000-------103B
2) brdet
trdt---------brn-----brtot-----------brcat
11-aug09--10-----454000-------A
09-aug-09-12-----550000-------B
30-sep-09--10-----430000------A
09-aug-09-11-----550000-------B
i want to display data for each branch refdet.refbr = brdet.brn
refdet
Br10
refdt----------refbr----refamt----refcat-----trdt---------brn-----brtot-----------brcat
10-aug-09---10-----34234-----101a-------11-aug09--10-----454000-------A
1-AUG-09----10----455.98----104A------30-sep-09--10-----430000------A
Br 11
10-aug-009--11----23245-----102a -------09-aug-09-11-----550000-------B
Br12
19-aug-09-12-----10000-------103B------09-aug-09----12-----550000-------B
i tried the following query but its not working
select distinct null as refdt,null as refbr,null as refamt,null as refcat,b.trdt,b.brn,b.brtot,b.brcat
from brdet a,refdet b
where a.refbr (+) = b.brn
union all
select distinct a.refdt,a.refbr,a.refamt,a.refcat,null as trdt,null as brn,null as brtot,null as brcat
from brdet a,refdet b
where a.refbr = b.brn (+)
its not giving the records on each row for both side its creating separte rows for each records in both table.
rgds
jytohi
-Hi jytohi,
Please lean back for a moment and study your question. Ask yourself, is this a reasonable way to ask a question?
Jopefully you'll reach the answer, "No it isn't, I need to.."
1. Turn these
1)
refdt----------refbr----refamt----refcat
2) brdet
trdt---------brn-----brtot-----------brcatinto CREATE TABLE statements.
2. Turn these
10-aug-09---10-----34234-----101a
10-aug-009--11----23245-----102a
1-AUG-09----10----455.98----104A
19-aug-09-12-----10000-------103B
11-aug09--10-----454000-------A
09-aug-09-12-----550000-------B
30-sep-09--10-----430000------A
09-aug-09-11-----550000-------Binto INSERT INTO statements
3. Turn this
refdet
Br10
refdt----------refbr----refamt----refcat-----trdt---------brn-----brtot-----------brcat
10-aug-09---10-----34234-----101a-------11-aug09--10-----454000-------A
1-AUG-09----10----455.98----104A------30-sep-09--10-----430000------A
Br 11
10-aug-009--11----23245-----102a -------09-aug-09-11-----550000-------B
Br12
19-aug-09-12-----10000-------103B------09-aug-09----12-----550000-------Binto properly formatted expected output, along with a reasonable explanation of why
4. Turn this
select distinct null as refdt,null as refbr,null as refamt,null as refcat,b.trdt,b.brn,b.brtot,b.brcat
from brdet a,refdet b
where a.refbr (+) = b.brn
union all
select distinct a.refdt,a.refbr,a.refamt,a.refcat,null as trdt,null as brn,null as brtot,null as brcat
from brdet a,refdet b
where a.refbr = b.brn (+)into a properly formatted query
And last, put everything in into curly brackets {noformat}{noformat} to preserve formatting and blank space.
Best regards
Peter -
Alternative way to fetch the data into single row.
we have a query
SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME='XXX';
This query will return the data in multiple rows.
May know the alternative way to retrieve all the multiple rows in **single row with each row as a seperate column**.Why specifically an array - and do you want the SQL projection as an array, or collect the SQL projection into an array?
E.g.
SQL> create or replace type TStrings is table of varchar2(4000);
2 /
Type created.
SQL> --// SQL projection casted into an array
SQL> select
2 cast(
3 MultiSet(
4 select column_name from all_tab_columns where table_name = 'KU$_DATAPUMP_MASTER_11_2' and owner = 'SYS'
5 )
6 as TStrings
7 ) as COLUMN_ARRAY
8 from dual
9 /
COLUMN_ARRAY
TSTRINGS('REMOTE_LINK', 'VERSION', 'JOB_VERSION', 'DB_VERSION', 'TIMEZONE', 'STATE', 'PHASE', 'GUID', 'START_TIME', 'BLOCK_SIZE', 'METADATA_BUFFER_SIZE', 'DATA_BUFFER_SIZE', 'DEGREE', 'PLATFORM', 'ABO
RT_STEP', 'INSTANCE', 'CLUSTER_OK', 'SERVICE_NAME', 'OBJECT_INT_OID', 'PROCESS_ORDER', 'DUPLICATE', 'DUMP_FILEID', 'DUMP_POSITION', 'DUMP_LENGTH', 'DUMP_ORIG_LENGTH', 'DUMP_ALLOCATION', 'COMPLETED_ROW
S', 'ERROR_COUNT', 'ELAPSED_TIME', 'OBJECT_TYPE_PATH', 'OBJECT_PATH_SEQNO', 'OBJECT_TYPE', 'IN_PROGRESS', 'OBJECT_NAME', 'OBJECT_LONG_NAME', 'OBJECT_SCHEMA', 'ORIGINAL_OBJECT_SCHEMA', 'ORIGINAL_OBJECT
_NAME', 'PARTITION_NAME', 'SUBPARTITION_NAME', 'DATAOBJ_NUM', 'FLAGS', 'PROPERTY', 'TRIGFLAG', 'CREATION_LEVEL', 'COMPLETION_TIME', 'OBJECT_TABLESPACE', 'SIZE_ESTIMATE', 'OBJECT_ROW', 'PROCESSING_STAT
E', 'PROCESSING_STATUS', 'BASE_PROCESS_ORDER', 'BASE_OBJECT_TYPE', 'BASE_OBJECT_NAME', 'BASE_OBJECT_SCHEMA', 'ANCESTOR_PROCESS_ORDER', 'DOMAIN_PROCESS_ORDER', 'PARALLELIZATION', 'UNLOAD_METHOD', 'LOAD
_METHOD', 'GRANULES', 'SCN', 'GRANTOR', 'XML_CLOB', 'PARENT_PROCESS_ORDER', 'NAME', 'VALUE_T', 'VALUE_N', 'IS_DEFAULT', 'FILE_TYPE', 'USER_DIRECTORY', 'USER_FILE_NAME', 'FILE_NAME', 'EXTEND_SIZE', 'FI
LE_MAX_SIZE', 'PROCESS_NAME', 'LAST_UPDATE', 'WORK_ITEM', 'OBJECT_NUMBER', 'COMPLETED_BYTES', 'TOTAL_BYTES', 'METADATA_IO', 'DATA_IO', 'CUMULATIVE_TIME', 'PACKET_NUMBER', 'INSTANCE_ID', 'OLD_VALUE', '
SEED', 'LAST_FILE', 'USER_NAME', 'OPERATION', 'JOB_MODE', 'QUEUE_TABNUM', 'CONTROL_QUEUE', 'STATUS_QUEUE')
SQL> --// collecting the SQL projection as an array
SQL> declare
2 colArray TStrings;
3 begin
4 select
5 column_name bulk collect into colArray
6 from all_tab_columns
7 where table_name = 'KU$_DATAPUMP_MASTER_11_2'
8 and owner = 'SYS';
9
10 --// process array
11 end;
12 /
PL/SQL procedure successfully completed.
SQL> -
thanks
Edited by: 786304 on May 25, 2011 12:22 PMBluShadow .
I agree your opinion.
I resurrect it from google cache.
Hi All,
I have two queries as follows
Select
Xrc.Profile_Nbr Var_Profile_Nbr,
xsr.Profile_Nbr Var_Profile_Nbr,
Nvl(Ppa.First_Name,' ') Var_First_Name,
Nvl(Ppa.Last_Name,' ') Var_Last_Nmae,
Nvl(Ppa.Last_Name2,' ') Var_Last_Name2,
Nvl(Ppa.Middle_Name,' ') Var_Middle_Name,
Nvl(Pfl.Display_Name,' ') Var_Display_Name,
Nvl(Addr.Street1,' ') Var_Street1,
Nvl(Addr.Street2,' ') Var_Street2,
Nvl(Addr.City,' ') Var_City ,
Nvl(Addr.State_Name,' ') Var_State_Name,
Addr.Post_Code Var_Post_Code,
Nvl(Cnt.Cntry_Name,' ') Var_Country,
Phn.Phone Var_Phone_Nbr,
Nvl(To_Char(Ppa.Birthdate,'MON/DD/YYYY'),' ') Var_Birthdate,
Nvl(Ppa.Occupation,' ') Var_Occupation,
Nvl(Ppa.Country_Of_Nationality,1) Var_Country_Of_Nationality,
Nvl(Ppa2.First_Name,' ') Var_First_Name,
Nvl(Ppa2.Last_Name,' ') Var_Last_Nmae,
Nvl(Ppa2.Last_Name2,' ') Var_Last_Name2,
Nvl(Ppa2.Middle_Name,' ') Var_Middle_Name,
Nvl(Pfl2.Display_Name,' ') Var_Display_Name,
Nvl(Addr2.Street1,' ') Var_Street1,
Nvl(Addr2.Street2,' ') Var_Street2,
Nvl(Addr2.City,' ') Var_City ,
Nvl(Addr2.State_Name,' ') Var_State_Name,
Addr2.Post_Code Var_Post_Code,
Nvl(Cnt2.Cntry_Name,' ') Var_Country,
Phn2.Phone Var_Phone_Nbr,
Nvl(To_Char(Ppa2.Birthdate,'MON/DD/YYYY'),' ') Var_Birthdate,
Nvl(Ppa2.Occupation,' ') Var_Occupation,
Nvl(ppa2.COUNTRY_OF_NATIONALITY,1) var_COUNTRY_OF_NATIONALITY
From
V_Xact_Receiver Xrc, V_Person_Profile Ppa, V_Profile Pfl,V_Phone Phn,V_Address Addr,V_Country_Lu Cnt
,V_Xact_sender xsr, V_Person_Profile Ppa2, V_Profile Pfl2,V_Phone Phn2,V_Address Addr2,V_Country_Lu Cnt2
Where Xrc.Xact_Hdr_Nbr=71138142
and xsr.Xact_Hdr_Nbr=71138142
And xrc.Profile_Nbr=Ppa.Profile_Nbr
And Ppa.Profile_Nbr=Pfl.Profile_Nbr
And Pfl.Profile_Nbr=Phn.Profile_Nbr
And Pfl.Profile_Nbr=Addr.Profile_Nbr
And Phn.Country_Nbr=Cnt.Country_Nbr
And Xsr.Profile_Nbr=Ppa2.Profile_Nbr
And Ppa2.Profile_Nbr=Pfl2.Profile_Nbr
And Pfl2.Profile_Nbr=Phn2.Profile_Nbr
And Pfl2.Profile_Nbr=Addr2.Profile_Nbr
And Phn2.Country_Nbr=Cnt2.Country_Nbr;
and
SELECT
Nvl(Dlu.Id_Type_Desc,' ') Var_Ident_Type_Desc,
Nvl(D.Id_Number,' ') Var_Id_Number,
Nvl(To_Char(D.Id_Issue_Date,'MON/DD/YYYY'),' ') Dte_Id_Issue,
Nvl(To_Char(D.Id_Expiration_Date,'MON/DD/YYYY'),' ') Dte_Id_Expiration,
Nvl(To_Char(Id_Expiration_Date,'MON/DD/YYYY'),' ') Dte_Id_Expiration,
Nvl(D.Id_Issue_Place,' ') Var_Issue_Loc,
Nvl(Pfl.Occupation,' ') Var_Occupation,
Nvl(To_Char(Pfl.Birthdate,'MON/DD/YYYY'),' ') Dte_Birth,
Nvl(To_Char(Pfl.Country_Of_Nationality,'MON/DD/YYYY'),' ') Var_Country_Of_Nationality
FROM V_PROFILE_IDENT D,
V_ID_TYPE_LU DLU,
V_Country_Lu Clu,
V_Xact_sender Xsr,
v_person_profile pfl
Where Xsr.Xact_Hdr_Nbr='71138142'
And D.Profile_Nbr = Xsr.Profile_Nbr
and D.Profile_Nbr=pfl.Profile_Nbr
And D.Id_Type_Nbr = Dlu.Id_Type_Nbr
And D.Country_Nbr = Clu.Country_Nbr(+)
And D.Is_Valid = 'Y'
and rownum<=3;
The first query it returns the result in a single row
The second query it returns the output in 3 rows
while i was club these two it gives the result in 3 rows
but have to get the result in a single row with all appropriate values side by side if the values are same get the values one only
and the query club as
Select
Xrc.Profile_Nbr Var_Profile_Nbr,
xsr.Profile_Nbr Var_Profile_Nbr,
Nvl(Ppa.First_Name,' ') Var_First_Name,
Nvl(Ppa.Last_Name,' ') Var_Last_Nmae,
Nvl(Ppa.Last_Name2,' ') Var_Last_Name2,
Nvl(Ppa.Middle_Name,' ') Var_Middle_Name,
Nvl(Pfl.Display_Name,' ') Var_Display_Name,
Nvl(Addr.Street1,' ') Var_Street1,
Nvl(Addr.Street2,' ') Var_Street2,
Nvl(Addr.City,' ') Var_City ,
Nvl(Addr.State_Name,' ') Var_State_Name,
Addr.Post_Code Var_Post_Code,
Nvl(Cnt.Cntry_Name,' ') Var_Country,
Phn.Phone Var_Phone_Nbr,
Nvl(To_Char(Ppa.Birthdate,'MON/DD/YYYY'),' ') Var_Birthdate,
Nvl(Ppa.Occupation,' ') Var_Occupation,
Nvl(Ppa.Country_Of_Nationality,1) Var_Country_Of_Nationality,
Nvl(Ppa2.First_Name,' ') Var_First_Name,
Nvl(Ppa2.Last_Name,' ') Var_Last_Nmae,
Nvl(Ppa2.Last_Name2,' ') Var_Last_Name2,
Nvl(Ppa2.Middle_Name,' ') Var_Middle_Name,
Nvl(Pfl2.Display_Name,' ') Var_Display_Name,
Nvl(Addr2.Street1,' ') Var_Street1,
Nvl(Addr2.Street2,' ') Var_Street2,
Nvl(Addr2.City,' ') Var_City ,
Nvl(Addr2.State_Name,' ') Var_State_Name,
Addr2.Post_Code Var_Post_Code,
Nvl(Cnt2.Cntry_Name,' ') Var_Country,
Phn2.Phone Var_Phone_Nbr,
Nvl(To_Char(Ppa2.Birthdate,'MON/DD/YYYY'),' ') Var_Birthdate,
Nvl(Ppa2.Occupation,' ') Var_Occupation,
Nvl(Ppa2.Country_Of_Nationality,1) Var_Country_Of_Nationality,
Nvl(Dlu.Id_Type_Desc,' ') Var_Ident_Type_Desc,
Nvl(D.Id_Number,' ') Var_Id_Number,
Nvl(To_Char(D.Id_Issue_Date,'MON/DD/YYYY'),' ') Dte_Id_Issue,
Nvl(To_Char(D.Id_Expiration_Date,'MON/DD/YYYY'),' ') Dte_Id_Expiration,
Nvl(To_Char(Id_Expiration_Date,'MON/DD/YYYY'),' ') Dte_Id_Expiration,
Nvl(D.Id_Issue_Place,' ') Var_Issue_Loc,
Nvl(Pfl3.Occupation,' ') Var_Occupation,
Nvl(To_Char(Pfl3.Birthdate,'MON/DD/YYYY'),' ') Dte_Birth,
Nvl(To_Char(Pfl3.Country_Of_Nationality,'MON/DD/YYYY'),' ') Var_Country_Of_Nationality
From
V_Xact_Receiver Xrc, V_Person_Profile Ppa, V_Profile Pfl,V_Phone Phn,V_Address Addr,V_Country_Lu Cnt
,V_Xact_sender xsr, V_Person_Profile Ppa2, V_Profile Pfl2,V_Phone Phn2,V_Address Addr2,V_Country_Lu Cnt2
V_Profile_Ident D,
V_Id_Type_Lu Dlu,
V_Country_Lu Clu,
V_Xact_receiver Xrc2,
v_person_profile pfl3
Where Xrc.Xact_Hdr_Nbr=71138142
And Xsr.Xact_Hdr_Nbr=71138142
and xrc2.Xact_Hdr_Nbr=71138142
And xrc.Profile_Nbr=Ppa.Profile_Nbr
And Ppa.Profile_Nbr=Pfl.Profile_Nbr
And Pfl.Profile_Nbr=Phn.Profile_Nbr
And Pfl.Profile_Nbr=Addr.Profile_Nbr
And Phn.Country_Nbr=Cnt.Country_Nbr
And Xsr.Profile_Nbr=Ppa2.Profile_Nbr
And Ppa2.Profile_Nbr=Pfl2.Profile_Nbr
And Pfl2.Profile_Nbr=Phn2.Profile_Nbr
And Pfl2.Profile_Nbr=Addr2.Profile_Nbr
And Phn2.Country_Nbr=Cnt2.Country_Nbr
And D.Profile_Nbr = Xrc2.Profile_Nbr
and D.Profile_Nbr=pfl3.Profile_Nbr
And D.Id_Type_Nbr = Dlu.Id_Type_Nbr
And D.Country_Nbr = Clu.Country_Nbr(+)
And D.Is_Valid = 'Y'
and rownum<=3;
regards, -
Can we make a fact column to be displayed as a single ROW in obiee 11g
Hi,
I have a requirement recently, where i need to show a fact column which shows the total value, as a single row in the main report.
Total
1000
1000
1000
1000
Changed to..
Total
1000
Can we achieve this in OBIEE.
Please share your inputs. Much Appreciate it !
Thanks,
RamyaShailja,
Yes you can. Follow these steps:
1> Create the LOV (which you can create from another table, as you mention). and test it.
2> Now you create one ADF Table on the page.
3> Select the Table in staructure window > select af:column(the column where you want put you lov) > Inside the af:column, Replace the Uicomponent by the LOV(which you created in step-1)
4> Save & Run
--Neelmani Jaiswal
http://www.jneelmani.blogspot.com -
Converting multi-row data to single row
My source table has one or more records with the same id. My destination table only has one record for each id. I wish to combine the records from my source table to my destination table. I think the following query will show what I'm trying to do:
update TARGET_TABLE
set (A)
=
(select (case
when sum(A*FUEL_TYPE_ID) > 2 then 4
else sum(A*FUEL_TYPE_ID)
end)
from SOURCE_TABLE
group by additive_id)
where additive_id = NEW_TABLE.additive_idSince I'm currently limited to Apex SQL Commands, the error information is minimalist:
ORA-01427: single-row subquery returns more than one row
How should I be doing this?Hi tharpa,
Are u able to relate to this.
create table emp2 as select * from emp;
update emp2
set sal=(
select sum(sal)
from emp
group by deptno)
where empno=7839
-------correct one would be-------
update emp2 e2
set sal=(
select sum(sal)
from emp e1
where e1.deptno=e2.deptno
group by deptno)
where empno=7839
Hope it helps
CKLP
Edited by: CKLP on Apr 11, 2011 5:17 AM -
How to get multiple row data in single row for one value of foreign key
i want to get data from a table in a way that all the emp_id corresponding to one manager_id
in employee table come in one row. (emp_id is the primary key and manager_id is the foreign key) Since there are different emp_id whose manager_id is same
so how can i get all the emp_id in one row .One way with 10g:
select mgr,
rtrim(xmlagg(xmlelement(empno,empno||',').extract('//text()')),',') emps
from emp
where mgr is not null
group by mgr;10g:
-- define this function:
create or replace
function concatenate(c Sys_refcursor, sep varchar2 default null) return varchar2
as
val varchar2(100);
return_value varchar2(4000);
begin
-- open c;
loop
fetch c into val;
exit when c%notfound;
if return_value is null then
return_value:=val;
else
return_value:=return_value||sep||val;
end if;
end loop;
return return_value;
end;
select mgr,
concatenate(cursor(select empno from emp e where e.mgr=emp.mgr order by empno),',')
from emp
where mgr is not null
group by mgr;With 11g:
select mgr,
listagg(empno,',') within group (order by empno) emps
from emp
where mgr is not null
group by mgr; -
I'm busy re-oredering data.
I have the follwing problem:
I've a column with data that must become unique, but there are values that occur more than once. I've to append 0, 1,2, etc to these values in order to make the values unique.
eg.
[b]Current situation
aplha
alpha
alpha
Desired
alpha1
alpha2
alpha3
how can I realize this in PL/SQL? tnx in advance.Similar:
SQL> INSERT INTO emp
SELECT 9999 empno,
ename,
job,
mgr,
hiredate,
sal,
comm,
40 deptno
FROM emp
WHERE empno = 7788
1 row created.
SQL> SELECT deptno,
deptno || DECODE (cnt, 1, NULL, rn) new_deptno
FROM (SELECT deptno,
ROW_NUMBER () OVER (PARTITION BY deptno ORDER BY deptno) rn,
COUNT (*) OVER (PARTITION BY deptno) cnt
FROM emp)
DEPTNO NEW_D
10 101
10 102
10 103
20 201
20 202
20 203
20 204
20 205
30 301
30 302
30 303
30 304
30 305
30 306
40 40
15 rows selected. -
SQL Multiple Columns Displayed in a Single Row
Hello everyone,
I have 2 tables, Product and Product_Name, one Product can have more than one name.
I need to retrieve it in such a way that I show the Product_ID followed by all the names this product has.
I'm not able to make it, every way I try I get the Product ID duplicated and several rows with a different product name on each row as follows:
1, 'Iron Z"
1, 'Iron M'
1, 'Iron N'
2, 'Wood P'
2, 'Wood M'
What I need is:
1, Iron Z, Iron M, Iron N
2, Wood P, Wood M
Thanks and Regards.Hi,
user10103934 wrote:
Thank you for the answer Frank,
Iron Z, Iron M and Iron N would be 3 different entries on the same column.
I'm sure the LISTAGG function would resolve this, the problem is that I was hoping to get a solution on pure SQL or PL/SQL, maybe with a nested Select.
My Oracle version is 10g Express Edition.LISTAGG is pure SQL, but it was only introduced in Oracle 11.2. Everything mentioned below should work in Oracle 10.
The STRAGG function from that page is very useful. You have to copy and install about 60 line of PL/SQL code. Do that once, and then you can use it hundreds of times in hundreds of queries, just as if it was a built-in function. The main problem with STRAGG is that it's hard to get soprted output from it. There's a modified version, designed for sorted output, on this thread:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:15637744429336
Never used it. Can't vouch for it.
SYS_CONNECT_BY_PATH seems to be the most popular way of doing string aggregation in Oracle 10. The example given on the Oracle Base page (which I posted in my last message) is a little clumsy and inefficient. See the following thread for a better example, using CONNECT_BY_ISLEAF:
Re: Concatenate strings from more rows into one row.
or, now that I see it, Pollywog's example above.
Edited by: Frank Kulash on Jun 11, 2010 2:24 PM -
How to display the vertical coloumns(records) in a single row?
Hi all,
I need a requirement in SAP where in the internal table records are in vertical placement as follows:
1 2 3 4 5 | a1 b1 c1 d1 e1
1 2 3 4 5 | a2 b2 c2 d2 e2
1 2 3 4 5 | a3 b3 c3 d3 e3
and so on..........
now as per the requirement I need all the records to be displayed in a single row in the output as follows:
1 2 3 4 5 | a1 b1 c1 d1 e1 | a2 b2 c2 d2 e2 | a3 b3 c3 d3 e3 |.....so on
Any pointers on this would be of great help.
thanks in advance,
Vamsee.Loop at itab.
at new f1.
write : itab-f1. <--- here don't give '/' .. which will write in new line ...
endif.
write : itab-f2, <--- here don't give '/' .. which will write in new line ...
itab-f3,
itab-f4,
itab-f5,
itab-f6.
at end of f1.
write :/ ''.
endat.
endloop. -
Combining Multiple Rows into single row with multple columns
Hi Experts,
I have the following requirement, kindly help me.
I have data in my table like below.
ID NAME DEPT
1 Sam 10
1 Sam 20
2 alex 30
2 alex 40
2 alex 50
3 vinod 60
3 vinod 70
I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.
ID NAME DEPT1 DEPT2 DEPT3
1 Sam 10 20
2 alex 30 40 50
3 vinod 60 70
It's urgent requirement, kindly help me.
Thanks in advance.Right I've had my drink, so what was this "urgent" question then?
798616 wrote:
I have data in my table like below.
ID NAME DEPT
1 Sam 10
1 Sam 20
2 alex 30
2 alex 40
2 alex 50
3 vinod 60
3 vinod 70
I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.Dynamic numbers of columns eh! Tricky.
If you understand how SQL statements are executed it's along these lines...
1. Open Cursor
2. Parse SQL statement and determine columns
3. Bind in any input values
4. Fetch data
5. Bind out values to columns
6. Repeat step 3 until no more data
7. Close cursor
Now, you're expecting that you can determine the columns (step 2) from the fetched data (step 4 onwards). You can't. The SQL engine needs to know the expected columns before any data is fetched so, it can't base the number of columns on the data itself.
If you need that requirement, you would need to query the data first and build up a dynamic query based on the data and then execute that dynamically built query to fetch the data and pivot it into those columns, which means that you have queried the data twice. Not good practice and not good (or simple) coding.
What you're talking of doing is something that should be handled at the presentation/interface layer, not as part of the data fetch.
Typically these sorts of things are handled most easily in report generation/writer tools such as Oracle Reports, Business Objects etc. where they fetch the data from the database and then process it to format it on the display, pivoting the results as required.
It's not something that lends itself to be easily achieved in SQL. Yes, SQL can do pivoting of data quite easily, but NOT with a dynamic number of columns.
If you were to specify that there is a maximum number of columns that you could get (rather than wanting it dynamic), then you can do it simply in SQL with the max-decode method...
SQL> ed
Wrote file afiedt.buf
1 with t as (select deptno, ename, row_number() over (partition by deptno order by ename) as rn from emp)
2 --
3 select deptno
4 ,max(decode(rn,1,ename)) as ename1
5 ,max(decode(rn,2,ename)) as ename2
6 ,max(decode(rn,3,ename)) as ename3
7 ,max(decode(rn,4,ename)) as ename4
8 ,max(decode(rn,5,ename)) as ename5
9 ,max(decode(rn,6,ename)) as ename6
10 ,max(decode(rn,7,ename)) as ename7
11 ,max(decode(rn,8,ename)) as ename8
12 ,max(decode(rn,9,ename)) as ename9
13 ,max(decode(rn,10,ename)) as ename10
14 from t
15 group by deptno
16* order by deptno
SQL> /
DEPTNO ENAME1 ENAME2 ENAME3 ENAME4 ENAME5 ENAME6 ENAME7 ENAME8 ENAME9 ENAME10
10 CLARK KING MILLER
20 ADAMS FORD JONES SCOTT SMITH
30 ALLEN BLAKE JAMES MARTIN TURNER WARD
SQL> -
Unable to reorder/change column names on interactive single row view
I have created an interactive report and grouped my columns to display nicely in a single row view report. However, once I initially add the columns to a group, I am unable to reorder them. I can move them up and down the list, but the changes don't save. Also, I have gone through column by column and unchecked the box that says Use Same Text for Single Row View and expanded the column name. However, the single row view still displays what is in the master report. I've tried closing out my browser completely and reopening, but I am still not seeing my changes. Any suggestions?
I also just stumbled about the "Use Same Text for Single Row View" option actually doing nothing - in Single Row View I still get the label text from "Column Heading", no matter what I enter in "Single Row View Label".
I had to adjust a column width using a span tag in the heading (as this seems to be the only way to do that - any other suggestions I found adding style information to the region header had no effect), and now that tag is displayed in the Single Row View label.
I can live with that for now, but it's not really nice.
Is this a known bug? Didn't find anything else in the forum regarding this problem so far.
Holger -
How to manipulate data in multiple rows without using cursor??
Hi all,
I have a form in which there is a push button & 4 text fields.
Push button : Process
Text fields: Year, Month, Financial_To_Year, Financial_From_Date.
In database , there are tables like, CUSTOMER_MASTER, FD_ACCOUNT_MASTER, FD_ACCOUNT_DTL, CUSTOMER_YEARLY_INTEREST, etc.
In table FD_ACCOUNT_MASTER, there are columns, like CUST_CODE, FD_ACCT_NO, FD_AMOUNT, ACCT_OPEN_DT, ACCT_CLOSE_DATE, ACCT_TYPE, INTEREST_RATE, etc.
There are thousands of records in the table.
For Push button : Process , TRIGGER: When button pressed,
I have to do all the process of FD for all the FD_ACCOUNTS at once. Process means i have to calculate Interest for all the accounts, calculate interest monthly, quarterly, yearly and make the FD_Accounts disable after the date of ACCT_CLOSE_DATE is reached, make the accounts renewed , etc all the process.
But to do this process for multiple rows at once, we use cursor, but i don't want to use cursor as i feel its too tedious to do.
Is there any other way , where i do process of multiple records at once without using cursor??
Help me, Thank You.
Oracle Forms Builder 6i.
Oracle9i Enterprise Edition Release 9.2.0.1.0 - ProductionAn Update statement certainly can update sets of data instead single row updates:
UPDATE Statement
if you can't do it in a single statement you can use bulk processing as well:
PLSQL 101
cheers -
Display of data in a single row
Hi
Here is my query:
SELECT
--Element Classification Details:
pec.CLASSIFICATION_ID,
pec.classification_name,
pec1.classification_id "Sub Classification Id",
DECODE(pec1.classification_name,'Other Deductions', 'Other Deductions',
'Others Voluntary Deductions', 'Other Deductions',
'Personal Deductions', 'Personal Deductions',
'Personal Voluntary Deductions', 'Personal Deductions',
'Car Loan Deductions') "Sub Classification",
pec1.parent_classification_id,
scr.sub_classification_rule_id,
--Element Details:
pet.element_name, pet.element_type_id, pet.reporting_name,
DECODE(pet.processing_type, 'R', 'Recurring', 'Nonrecurring') "Processing Type",
pet.EFFECTIVE_START_DATE, pet.EFFECTIVE_END_DATE,
--Run Result Details:
prr.run_result_id,
TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)) "Amount",
piv.NAME "Input Value",
--Assignment Details:
paa.assignment_id,
--Time Period
ptp.START_DATE, ptp.end_date,
ptp.period_name "Payroll Period"
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv,
hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
AND paa.payroll_id != 0
AND paa.pay_basis_id != 0
AND paa.ASSIGNMENT_ID = '560'
I needed to display the amounts as separate columns pertaining to different elements or rather different sub classification of the elements
This is the final expected result for the report:
Employee Personal Deductions PD Amount Other Deductions OD Amt
XYZ Element1 00000.00 Element3 0000.00
Element 2
Car Loan Deductions CLD Amt Total Deductions (Total of all three)
Element4 00000.00 00000000.00
Here Personal Deductions, Other, Car Loan etc. are grouping of elements (sub classifications)
I have used MAX function to display the results as separate columns like this:
SELECT
--Run Result Details:
prr.run_result_id,
MAX(DECODE(pec1.classification_name, 'Personal Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Personal Deductions",
MAX(DECODE(pec1.classification_name, 'Personal Voluntary Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Personal V Deductions",
MAX(DECODE(pec1.classification_name, 'Other Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Other Deductions",
MAX(DECODE(pec1.classification_name, 'Others Voluntary Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Others V Deductions",
MAX(DECODE(pec1.classification_name, 'Car Loan Deductions', TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) "Car Loan Deductions"
/*--Assignment Details:
paa.assignment_id,
--Time Period
ptp.START_DATE, ptp.end_date,
ptp.period_name "Payroll Period"*/
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv
/*hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp*/
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
/*AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
--and pet.element_NAME like 'IVTB%'
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE*/
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
--and paa.PRIMARY_FLAG like 'Y%'
/*AND paa.payroll_id != 0
AND paa.pay_basis_id != 0*/
GROUP BY
prr.run_result_id
However, the fact is that my each element_type_id has each run_result_id, which means 1 element has 1 run result id. Thus, I cannot display the data in a single row.
Can someone guide me on this? How can I display the data for an employee as a single row?
Thanks and regards,
AparnaSELECT EMP_ID,
Sum(Decode(DECODE(pec1.classification_name,'Other Deductions', 'Other Deductions','Others Voluntary Deductions', 'Other Deductions'),'Other Deductions',TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Other deduction',
sum(Decode(DECODE(pec1.classification_name,'Personal Deductions', 'Personal Deductions', 'Personal Voluntary Deductions', 'Personal Deductions'),'Personal Deductions'),TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Personal deduction',
sum(DECODE(pec1.classification_name,'Car Loan Deductions',TO_NUMBER(NVL(prrv.RESULT_VALUE, 0)))) 'Car deduction'
FROM hr.pay_element_classifications pec,
hr.pay_element_classifications pec1,
hr.pay_sub_classification_rules_f scr,
hr.pay_element_types_f pet,
hr.pay_run_results prr,
hr.pay_run_result_values prrv,
hr.pay_input_values_f piv,
hr.pay_assignment_actions assact,
hr.per_all_assignments_f paa,
hr.pay_payroll_actions payroll,
hr.per_time_periods ptp
WHERE
pec.classification_id = pec1.parent_classification_id (+)
AND scr.classification_id = pec1.classification_id
AND pet.classification_id = pec.classification_id
AND scr.element_type_id = pet.element_type_id
AND pet.ELEMENT_TYPE_ID = prr.ELEMENT_TYPE_ID
AND prr.run_result_id = prrv.run_result_id
AND piv.input_value_id = prrv.input_value_id
AND assact.ASSIGNMENT_ACTION_ID = prr.ASSIGNMENT_ACTION_ID
AND paa.ASSIGNMENT_ID = assact.ASSIGNMENT_ID
AND payroll.payroll_action_id = assact.PAYROLL_ACTION_ID
AND ptp.TIME_PERIOD_ID = payroll.time_period_id
AND ptp.end_date BETWEEN scr.EFFECTIVE_START_DATE AND scr.EFFECTIVE_END_DATE
AND ptp.end_date BETWEEN pet.effective_start_date AND pet.effective_end_date
AND ptp.end_date BETWEEN paa.EFFECTIVE_START_DATE AND paa.EFFECTIVE_END_DATE
AND pec.CLASSIFICATION_NAME IN ('Voluntary Deductions', 'Pre-Tax Deductions')
AND pec1.classification_name LIKE '%Deduction%'
AND piv.name = 'Pay Value'
AND paa.payroll_id != 0
AND paa.pay_basis_id != 0
I hope this may help!
Brijesh
Maybe you are looking for
-
Time won't show in Menu; keeps disappearing
The upper right hand area of my MacBook Pro keeps disappearing and reappearing with the little wireless icons, bluetooth, etc. every few seconds. However, the time doesn't even appear when those items reappear. Also, most of my programs including Saf
-
RMAN backup in noarchived log mode
Hi, can we take RMAN backup in noarchived log mode? If yes, how? just run backup database command or ? thanks
-
Acrobat crashes during VB Script when workstation is locked
Very strange problem, maybe only related to my particular configuration but was hoping someone had some ideas. I've been working this issue for months and haven't been able to figure it out. I have an outlook macro that processes emails, downloads PD
-
Socket Connection - Character Set - Help
Hello: I am creating a socket using UTL_TCP package. After making a successful connection, I have to send data in ISO-8859 format. The message should look something like this. STX followed by data in ascii followed by ETX. STX and ETX are ascii for 2
-
Enterprise Structure -Sales Org to plant of company code
Hi, My client wants Sales Org to be assigned to plant of different company code. While doing configuration in our development system I got warning message that Sales Org,Distribution assigned to Plant is of different company code. Do we have any proc