How to convert multiple rows into colmun data?
Hi all
ODI has fuction that covert multiple rows form a file into colmun data?
Source:customer.txt
001,Scott
001,Man
001,23
002,Lincon
002,Man
002,21
objective Target:customer
ID Name Sex Age
001 Scott Man 23
002 Lincon Man 21
If there is no this fuction,how can I do this in ODI?
Thanks in advance.
Agui
Hi, Sanjeev,
What you requested is called String Aggregation.
Like most other things, the best way to do it depends on your version of Oracle.
The following site shows several different ways to do string aggregation:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php'
The user-defined function (often called STRAGG) that Charles mentioned is my favorite, in versions between 9.1 and 11.1.
Similar Messages
-
Convert multiple rows into single rows for the respective index name
Dear Experts,
I want to convert multiple rows into single rows for the respective index name,
Here is my query.
SELECT user_tables.table_name, user_indexes.index_name, user_ind_columns.column_name
FROM user_tables
JOIN user_indexes on user_indexes.table_name = user_tables.table_name
join USER_IND_COLUMNS on USER_INDEXES.INDEX_NAME = USER_IND_COLUMNS.INDEX_NAME
where user_indexes.index_name not like '%PK%' AND user_ind_columns.column_name NOT LIKE '%SYS%'
ORDER BY user_tables.table_name,user_indexes.index_name;
Result of previous query
TABLE_NAME
INDEX_NAME
COLUMN_NAME
T1
IDX_ACCNTYPCFG1
ENABLE_SERVICE
T1
IDX_ACCTTYPCFG1
ACC_CODE
T1
IDX_ACCTTYPCFG1
ACCTYPE
T2
IDX_ACCTTYPCFGAPP1
ACCTYPE
T3
IDX_ACTLG1
MOBILE_NO
T3
IDX_ACTLG1
ID
Desired output required is
TABLE_NAME
INDEX_NAME
COLUMN_NAME
T1
IDX_ACCNTYPCFG1
ENABLE_SERVICE,ACC_CODE,ACCTYPE
T2
IDX_ACCTTYPCFGAPP1
ACCTYPE
T3
IDX_ACTLG1
ACCTYPE,MOBILE_NO
please help.Maybe
with
user_tables as
(select 'T1' table_name,'IDX_ACCNTYPCFG1' index_name,'ENABLE_SERVICE' column_name from dual union all
select 'T1','IDX_ACCTTYPCFG1','ACC_CODE' from dual union all
select 'T1','IDX_ACCTTYPCFG1','ACCTYPE' from dual union all
select 'T2','IDX_ACCTTYPCFGAPP1','ACCTYPE' from dual union all
select 'T3','IDX_ACTLG1','MOBILE_NO' from dual union all
select 'T3','IDX_ACTLG1','ID' from dual
select table_name,
case index_name when 'IDX_ACCNTYPCFG1' then 'IDX_ACCTTYPCFG1' else index_name end index_name,
listagg(case column_name when 'ID' then 'ACCTYPE' else column_name end,',') within group (order by null) column_name
from user_tables
group by table_name,case index_name when 'IDX_ACCNTYPCFG1' then 'IDX_ACCTTYPCFG1' else index_name end
TABLE_NAME
INDEX_NAME
COLUMN_NAME
T1
IDX_ACCTTYPCFG1
ACCTYPE,ACC_CODE,ENABLE_SERVICE
T2
IDX_ACCTTYPCFGAPP1
ACCTYPE
T3
IDX_ACTLG1
ACCTYPE,MOBILE_NO
Regards
Etbin -
Trying to convert multiple rows into multipe columns within a single row
I am trying to convert data from multiple rows into multiple columns. Let me see if I can paint the picture for you.
Here is a sample of the table i am trying to read from:
Company Name Account
1 Sam 123
1 Sam 234
1 Joe 345
1 Sue 789
1 Sue 987
1 Sue 573
I am trying to put this into a View that would have the data represented as such:
Company Name Acct1 Acct2 Acct3 Acct4
1 Sam 123 234 <null> <null>
1 Joe 345 <null> <null> <null>
1 Sue 789 987 573 <null>
Many thanks in advance for your help!test@XE> --
test@XE> with t as (
2 select 1 as company, 'Sam' as name, 123 as account from dual union all
3 select 1, 'Sam', 234 from dual union all
4 select 1, 'Joe', 345 from dual union all
5 select 1, 'Sue', 789 from dual union all
6 select 1, 'Sue', 987 from dual union all
7 select 1, 'Sue', 573 from dual)
8 --
9 select company,
10 name,
11 max(case when rn = 1 then account else null end) as acct1,
12 max(case when rn = 2 then account else null end) as acct2,
13 max(case when rn = 3 then account else null end) as acct3,
14 max(case when rn = 4 then account else null end) as acct4
15 from (select company,
16 name,
17 account,
18 row_number() over (partition by company, name order by 1) as rn
19 from t)
20 group by company, name;
COMPANY NAM ACCT1 ACCT2 ACCT3 ACCT4
1 Joe 345
1 Sam 234 123
1 Sue 573 789 987
3 rows selected.
test@XE>
test@XE>isotope -
How to convert a row into a column with the row headers displayed as column in javaFx?
How do in convert a row of data into column of data to display as shown below:
Column1|Column2|Column3|Column4
C1 | C2 | C3 | C4
C5 | C6 | C7 | C8
How to convert the above default behavior to as below
Column1| C1 | C5
Column2| C2 | C6
Column3| C3 | C7
Column4| C4 | C8.
-
How to convert a string into orcle date format
i need some information about converting string into date format.i have string like '20-SEP-05' .so we have to convert into date formate like yy-mm-dd' (2005-09-20).how can we do it.
Here's some code to help. I can't remember what method uses what format though
public static java.sql.Date sqlDateValueOf( String dateString ) {
String stringDate = null;
if ( dateString == null || dateString.length() < 10 ) return null;
String strDay = "";
String strMonth = "";
String strYear = "";
if ( dateString.substring(4,5).equals( "-" ) ) {
strDay = dateString.substring(8, 10);
if ( strDay.length() < 2 ) strDay = "0" + strDay;
strMonth = dateString.substring(5, 7);
strMonth = dateString.valueOf(Integer.parseInt(strMonth) - 1);
if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
strYear = dateString.substring(0, 4);
stringDate = strDay + "-" + strMonth + "-" + strYear;
else if ( dateString.substring(2,3).equals( "-" ) ) {
strDay = dateString.substring(0, 2);
if ( strDay.length() < 2 ) strDay = "0" + strDay;
strMonth = dateString.substring(3, 5);
strMonth = String.valueOf(Integer.parseInt(strMonth) - 1);
if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
strYear = dateString.substring(6, 10);
stringDate = strDay + "-" + strMonth + "-" + strYear;
Calendar cal = Calendar.getInstance();
cal.set( Calendar.YEAR, Integer.parseInt( strYear ) );
cal.set( Calendar.MONTH, Integer.parseInt( strMonth ) );
cal.set( Calendar.DAY_OF_MONTH, Integer.parseInt( strDay ) );
java.sql.Date outDate = new java.sql.Date( cal.getTimeInMillis() );
return outDate;
public static String toDateString( java.util.Date date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Date date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Date date, String format) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat( format );
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Timestamp date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
} -
How to convert (multiple) rows output to multiple (columns)
Hii
I have wierd query. But not sure of how to get result out of it!!!
My query returns two rows for a query that i have posed.
Current Result
10
20
Expected Result
10 20
My problem here is i wanted the above two values to be stored in two variables in a single select statement.
If i use a cursor my problem will be solved.But i am not much intrested to use a cursor for a simple select statement.
is there any possibilty that i can convert the output of two rows to two columns??
I am using Oracle Release 10.1.0.2.0
Operating system Windows Xp.
People here will not appreciate the tags "Urgent". I know that :-(.
But some how i am forced to use this tag "urgent". Sorry for that.
If no answers i will in other way have to go to cursor :-(
Any help will be appreciated.
Thanks,
PavanAnother solution with model and you don't need a subquery
SELECT DEPT ,SUBSTR(LOCATION1,2) LOCATION1, SUBSTR(LOCATION2,2) LOCATION2,SUBSTR(LOCATION3,2) LOCATION3
FROM T
MODEL
RETURN UPDATED ROWS
PARTITION BY ( DEPT )
DIMENSION BY ( ROW_NUMBER() OVER (PARTITION BY DEPT ORDER BY LOCATION ) AS POSITION )
MEASURES ( location,CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION1 ,CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION2,
CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION3 )IGNORE NAV
RULES
UPSERT
ITERATE( 1000)
UNTIL ( PRESENTV(LOCATION[ITERATION_NUMBER+2],1,0) = 0)
( LOCATION1[0] =LOCATION1[0] || CASE WHEN ITERATION_NUMBER+1=1 THEN ',' || LOCATION1[ ITERATION_NUMBER+1] END,
LOCATION2[0] =LOCATION2[0] || CASE WHEN ITERATION_NUMBER+1=2 THEN ',' || LOCATION2[ ITERATION_NUMBER+1] END,
LOCATION3[0] =LOCATION3[0] || CASE WHEN ITERATION_NUMBER+1=3 THEN ',' || LOCATION3[ ITERATION_NUMBER+1] END )
ORDER BY DEPT
Demo
SQL> WITH T AS ( SELECT 'AB' DEPT,'MEB' LOCATION FROM DUAL UNION ALL
2 SELECT 'AB','MEB1' FROM DUAL UNION ALL
3 SELECT 'AB','MEB2' FROM DUAL UNION ALL
4 SELECT 'BC','MEB' FROM DUAL UNION ALL
5 SELECT 'BC','MEB' FROM DUAL UNION ALL
6 SELECT 'CD','MEN' FROM DUAL UNION ALL
7 SELECT 'CD','MEN' FROM DUAL
8 )
9 SELECT DEPT ,SUBSTR(LOCATION1,2) LOCATION1, SUBSTR(LOCATION2,2) LOCATION2,SUBSTR(LOCATION3,2)
LOCATION3
10 FROM T
11 MODEL
12 RETURN UPDATED ROWS
13 PARTITION BY ( DEPT )
14 DIMENSION BY ( ROW_NUMBER() OVER (PARTITION BY DEPT ORDER BY LOCATION ) AS POSITION )
15 MEASURES ( location,CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION1 ,CAST ( LOCATION AS
VARCHAR2(15)) AS LOCATION2,
16 CAST ( LOCATION AS VARCHAR2(15)) AS LOCATION3 )IGNORE NAV
17 RULES
18 UPSERT
19 ITERATE( 1000)
20 UNTIL ( PRESENTV(LOCATION[ITERATION_NUMBER+2],1,0) = 0)
21 ( LOCATION1[0] =LOCATION1[0] || CASE WHEN ITERATION_NUMBER+1=1 THEN ',' || LOCATION1[ I
TERATION_NUMBER+1] END,
22 LOCATION2[0] =LOCATION2[0] || CASE WHEN ITERATION_NUMBER+1=2 THEN ',' || LOCATION2[ ITER
ATION_NUMBER+1] END,
23 LOCATION3[0] =LOCATION3[0] || CASE WHEN ITERATION_NUMBER+1=3 THEN ',' || LOCATION3[ ITER
ATION_NUMBER+1] END )
24 ORDER BY DEPT
25 /
DE LOCATION1 LOCATION2 LOCATION3
AB MEB MEB1 MEB2
BC MEB MEB
CD MEN MEN
SQL>
SQL> -
How to convert a String into a date in yyyy-MM-dd using SimpleDateFormat?
Hi Guys,
I am using the following code
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class ValiDATE {
private static boolean validateDateFormat(String strDate) {
try {
SimpleDateFormat formatter = new SimpleDateFormat("yy-MM-dd");
try {
formatter.setLenient(false);
formatter.parse(strDate);
catch (ParseException e) {
// invalid date/datetime format
return false;
catch (Exception ignored) {
return true;
public static void main(String args[]){
System.out.println(validateDateFormat("11111-11-11"));
}In the above snippet even if I pass the string parameter as "11111-11-11" it returns a new date and hence prints TRUE in the console, but I want the date to be in yyyy-MM-dd format that is no of years shouldn't exceed 4 digits in all.
I don't want to use RegEx, I know this can be done using SimpleDateFormat, but would like to know how that can be done.
I think it has to do something with this . ( [http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html#year|http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html#year] )
Regards
ARJava.slogger wrote:
Yeah I have gone through the javaDoc and it says For formatting, if the number of pattern letters is 2, the year is truncated to 2 digits; otherwise it is interpreted as a number. The important part is:
JavaDoc:
Any other numeric string, such as a one digit string, a three or more digit string, or a two digit string that isn't all digits (for example, "-1"), is interpreted literally.
Do you know any workarounds else is using a Regex is the best approach?I don't see this as a problem. Everything behaves as designed and as is sensible.
So if you want to avoid dates with 5-digit numbers, I'd add something like:
if (parsedDate.after(CUTOFF_DATE)) {
throw new OhNoesThisIsEvilException("!");
} -
HOW TO COMBINE MULTIPLE ROWS INTO SINGLE ROWS
Hi,
I have a table with the following data:
CASE-1
TABLE -X
RNO FROM_SQN TO_SQN DATE
==========================================
991 9 11 2010-01-01
991 11 22 2010-01-01
991 22 33 2010-01-01
992 33 44 2010-01-01
I want to see the result data as follows:
RNO FROM_SQN TO_SQN DATE
==========================================
991 9 44 2010-01-01
CASE-2
TABLE -X
RNO FROM_SQN TO_SQN DATE
==========================================
991 9 11 2010-01-01
991 15 22 2010-01-01
991 22 34 2010-01-01
992 33 44 2010-01-01
I want to see the result data as follows:
RNO FROM_SQN TO_SQN DATE
==========================================
991 9 11 2010-01-01
991 15 44 2010-01-01
Please help me how to achieve this using SQL.
Edited by: 986725 on Feb 7, 2013 2:36 AMwith x as
select 991 rno, 9 from_sqn ,11 to_sqn ,to_date('2010-01-01','yyyy-mm-dd') dt
from dual union all
select 991, 15 ,22 ,to_date('2010-01-01','yyyy-mm-dd') from dual union all
select 991, 22 ,33 ,to_date('2010-01-01','yyyy-mm-dd') from dual union all
select 991, 33 ,44 ,to_date('2010-01-01','yyyy-mm-dd') from dual
x_with_group as
select rno,from_sqn,to_sqn,dt,
sum(sm) over(partition by rno,dt order by from_sqn) sm
from
select rno,from_sqn,to_sqn,dt,
from_sqn-
nvl(lag(to_sqn) over(partition by rno,dt order by from_sqn),0) sm
from x
select rno,min(from_sqn) from_sqn,max(to_sqn) to_sqn,dt
from x_with_group
group by rno,dt,sm
order by rno,dt,from_sqn;
RNO FROM_SQN TO_SQN DT
991 9 11 01-jan-2010
991 15 44 01-jan-2010 Edited by: jeneesh on Feb 7, 2013 4:59 PM
Assumed the date values are actually DATE types.
Partition on DT and RNO can be amended as per your requirement..
And assumed your sample data has a typo..
If your data is correct..
with x as
select 991 rno, 9 from_sqn ,11 to_sqn ,to_date('2010-01-01','yyyy-mm-dd') dt
from dual union all
select 991, 15 ,22 ,to_date('2010-01-01','yyyy-mm-dd') from dual union all
select 991, 22 ,33 ,to_date('2010-01-01','yyyy-mm-dd') from dual union all
select 992, 33 ,44 ,to_date('2010-01-01','yyyy-mm-dd') from dual
x_with_group as
select rno,from_sqn,to_sqn,dt,
sum(sm) over(order by from_sqn) sm
from
select rno,from_sqn,to_sqn,dt,
from_sqn-
nvl(lag(to_sqn) over(order by from_sqn),0) sm
from x
select min(rno) rno,min(from_sqn) from_sqn,max(to_sqn) to_sqn,min(dt) dt
from x_with_group
group by sm
order by rno,dt,from_sqn;
RNO FROM_SQN TO_SQN DT
991 9 11 01-jan-2010
991 15 44 01-jan-2010 Edited by: jeneesh on Feb 7, 2013 5:14 PM -
HOW TO CONVERT MULTY ROW INTO SINGAL ROW
Dear sir
Normaly we get output of select statement like
select department_name from departments;
DEPARTMENT_NAME
Administration
Marketing
Purchasing
Human Resources
Shipping
IT
Public Relations
Sales
Executive
Finance
Accounting
Treasury
Corporate Tax
Control And Credit
Shareholder Services
Benefits
Manufacturing
Construction
Contracting
Operations
IT Support
NOC
IT Helpdesk
Government Sales
Retail Sales
Recruiting
Payroll
27 rows selected.
But i won't output in one line like below it is posible
DEPARTMENT_NAME
Administration Marketing Purchasing Human Resources Shipping IT Public Relations Sales Executive Finance Accounting
Treasury Corporate Tax Control And Credit Shareholder Services Benefits Manufacturing Construction Contracting Operations IT Support NOC IT Helpdesk Government Sales Retail Sales Recruiting Payroll.Solomon Yakobson wrote:
Besides STRAGG you could use analytic functions + hierarchical query:CONNECT_BY_ISLEAF is preferable to using a count and compare:
SQL> ed
Wrote file afiedt.buf
1 with t as (
2 select 'Administration' dname from dual union all
3 select 'Marketing' dname from dual union all
4 select 'Purchasing' dname from dual union all
5 select 'Human Resources' dname from dual union all
6 select 'Shipping' dname from dual union all
7 select 'IT' dname from dual union all
8 select 'Public Relations' dname from dual union all
9 select 'Sales' dname from dual union all
10 select 'Executive' dname from dual union all
11 select 'Finance' dname from dual union all
12 select 'Accounting' dname from dual union all
13 select 'Treasury' dname from dual union all
14 select 'Corporate Tax' dname from dual union all
15 select 'Control And Credit' dname from dual union all
16 select 'Shareholder Services' dname from dual union all
17 select 'Benefits' dname from dual union all
18 select 'Manufacturing' dname from dual union all
19 select 'Construction' dname from dual union all
20 select 'Contracting' dname from dual union all
21 select 'Operations' dname from dual union all
22 select 'IT Support' dname from dual union all
23 select 'NOC' dname from dual union all
24 select 'IT Helpdesk' dname from dual union all
25 select 'Government Sales' dname from dual union all
26 select 'Retail Sales' dname from dual union all
27 select 'Recruiting' dname from dual union all
28 select 'Payroll' dname from dual
29 )
30 select ltrim(replace(sys_connect_by_path(dname,'|'),'|',' ')) as department_name
31 from (select dname, row_number() over (order by dname) as rn
32 from t)
33 where connect_by_isleaf = 1
34 connect by rn = prior rn+1
35* start with rn = 1
SQL> /
DEPARTMENT_NAME
Accounting Administration Benefits Construction Contracting Control And Credit Corporate Tax Executive Finance Government Sales
Human Resources IT IT Helpdesk IT Support Manufacturing Marketing NOC Operations Payroll Public Relations Purchasing Recruiting
Retail Sales Sales Shareholder Services Shipping Treasury
SQL> -
Convert multiple rows into a single row
Hi friends..
I have a table with the following information
SQL> select * from tsting;
A B C D E
10
10
10
29-MAY-09
TESTBut I need the following result..
A B C D E
10 10 10 29-MAY-09 TESTHello,
Try:
WITH test_data AS (
SELECT 10 A, NULL B, NULL C, NULL D, NULL E FROM DUAL UNION ALL
SELECT NULL A, 10 B, NULL C, NULL D, NULL E FROM DUAL UNION ALL
SELECT NULL A, NULL B, 10 C, NULL D, NULL E FROM DUAL UNION ALL
SELECT NULL A, NULL B, NULL C, TO_DATE('29-MAY-09','DD-MON-YY') D, NULL E FROM DUAL UNION ALL
SELECT NULL A, NULL B, NULL C, NULL D, 'TEST' E FROM DUAL)
-- end test data
SELECT MAX(A) A, MAX(B) B, MAX(C) C, MAX(D) D, MAX(E) E
FROM test_data;
A B C D E
10 10 10 29-MAY-09 TEST -
How to convert result rows into comma separated values
hi,
Version
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionQuery
Select distinct prcdr_code from procedure p where P.PRCDR_CTGRY_LKPCD='P' ;
Output
PRCDR_CODE
0001F
0001T
0002F
0002T
0003F
0003T
0004F
0005F
0005T
0006F
0006T
0007F
0007T
0008F
0008T
0009F
0009T
000VA
000VG
Desired Output
0001F,0001T,0002F,0002T .................
My work
i tried this .....
Select distinct wm_concat(prcdr_code) as re from procedure p where P.PRCDR_CTGRY_LKPCD='P' ;
But i got ORA-22813: operand value exceeds system limits error
Please help me ..Thanks,
P Prakash
Edited by: prakash on Jan 4, 2012 9:05 AMAggregating CLOB's....
user defined aggregate function can do it...
create or replace type clobagg_type as object
text clob,
static function ODCIAggregateInitialize(sctx in out clobagg_type) return number,
member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number,
member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number,
member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number
create or replace type body clobagg_type is
static function ODCIAggregateInitialize(sctx in out clobagg_type) return number is
begin
sctx := clobagg_type(null) ;
return ODCIConst.Success ;
end;
member function ODCIAggregateIterate(self in out clobagg_type, value in clob) return number is
begin
self.text := self.text || value ;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self in clobagg_type, returnvalue out clob, flags in number) return number is
begin
returnValue := self.text;
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self in out clobagg_type, ctx2 in clobagg_type) return number is
begin
self.text := self.text || ctx2.text;
return ODCIConst.Success;
end;
end;
create or replace function clobagg(input clob) return clob
deterministic
parallel_enable
aggregate using clobagg_type;
SQL> select trim(',' from clobagg(ename||',')) as enames from emp;
ENAMES
SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER
SQL> ed
Wrote file afiedt.buf
1 with t as
2 (select 'PFL' c1, 0 c2,110 c3 from dual union all
3 select 'LHL', 0 ,111 from dual union all
4 select 'PHL', 1, 111 from dual union all
5 select 'CHL', 2, 111 from dual union all
6 select 'DHL', 0, 112 from dual union all
7 select 'VHL', 1, 112 from dual union all
8 select 'CPHL', 0, 114 from dual union all
9 select 'WDCL', 1, 114 from dual union all
10 select 'AHL' ,2 ,114 from dual union all
11 select 'NFDL', 3, 114 from dual)
12 --
13 -- end of test data
14 --
15 select trim(clobagg(c1||' ')) as c1, c3
16 from (select * from t order by c3, c2)
17 group by c3
18* order by c3
SQL> /
C1 C3
PFL 110
LHL CHL PHL 111
DHL VHL 112
CPHL AHL NFDL WDCL 114 -
Merge multiple rows into single row (but multiple columns)
How to merge multiple rows into single row (but multiple columns) efficiently.
For example
IDVal IDDesc IdNum Id_Information_Type Attribute_1 Attribute_2 Attribute_3 Attribute_4 Attribute_5
23 asdc 1 Location USA NM ABQ Four Seasons 87106
23 asdc 1 Stats 2300 91.7 8.2 85432
23 asdc 1 Audit 1996 June 17 1200
65 affc 2 Location USA TX AUS Hilton 92305
65 affc 2 Stats 5510 42.7 46 9999
65 affc 2 Audit 1996 July 172 1100
where different attributes mean different thing for each Information_type.
For example for Information_Type=Location
Attribute_1 means Country
Attribute_2 means State and so on.
For example for Information_Type=Stats
Attribute_1 means Population
Attribute_2 means American Ethnicity percentage and so on.
I want to create a view that shows like below:
IDVal IDDesc IDNum Country State City Hotel ZipCode Population American% Other% Area Audit Year AuditMonth Audit Type AuditTime
23 asdc 1 USA NM ABQ FourSeasons 87106 2300 91.7 46 85432 1996 June 17 1200
65 affc 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
ThanksHi,
That's called Pivoting . The forum FAQ has a section on this subject: {message:id=9360005}
I hope this answers your question.
If not, post your best attempt, along with a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. (You did post the results you wanted, but they're very hard to read because they're not formatted. Use \ tags, as described in the forum FAQ, below.)
Explain, using specific examples, how you get the results you want from the data given.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0). This is always important, but especially so with pivots.
See the forum FAQ {message:id=9360002} -
How To Concatenate Column Values from Multiple Rows into a Single Column?
How do I create a SQL query that will concatenate column values from multiple rows into a single column?
Last First Code
Lesand Danny 1
Lesand Danny 2
Lesand Danny 3
Benedi Eric 7
Benedi Eric 14
Result should look like:
Last First Codes
Lesand Danny 1,2,3
Benedi Eric 7,14
Thanks,
David JohnsonStarting with Oracle 9i
select last, first, substr(max(sys_connect_by_path(code,',')),2) codes
from
(select last, first, code, row_number() over(partition by last, first order by code) rn
from a)
connect by last = prior last and first = prior first and prior rn = rn -1
start with rn = 1
group by last, first
LAST FIRST CODES
Lesand Danny 1,2,3
Benedi Eric 7,14Regards
Dmytro -
How do i convert multiple tracks into one large mp3?
how do i convert multiple tracks into one large mp3?
Hi,
You can use an app such as Audacity or Join Together to create one larger file. If AAC file used instead of mp3, you could use GarageBand.
If you have the original CD, you can join the tracks whilst re importing disc.
Jim -
Reg : Passing multiple rows of table data to the RFC
Hi,
I am passing one row of data from webdynpro table to table of RFC.
How to pass multiple rows of data.
Please help me out.
Thanks
Rishahi
Person--->node(cardinality 1..n)
FirstName-->Attribute
LastName-->Attribute.
Person1-->RFC table node.(cardinality 1..n)
FName-->Attribute
LName-->Attribute
for(int i=0;i<wdContext.nodePerson().size();i++)
//Retrieving values from table
IPrivate<View>.IPersonElement element1=wdContext.nodePerson().createPersonElement();
String fname=element1.getFirstName();
String lname= element1.getLastName();
wdContext.nodePerson().addElement(element1);
//Inserting into table of RFC
IPrivate<View>.IPerson1Element element2=wdContext.nodePerson1().createPerson1Element();
element2.setFname(fname);
element2.setLname(lname);
wdContext.nodePerson1().addElement(element2);
Regards
sowmya.
Maybe you are looking for
-
Post incoming payments based on Invoice number.
Hello, I would appreciate your help on the following question. POINTS AVAILABLE. <b>Is there a way for us to post an incoming partial payment from a customer based only on the invoice number?</b> For example, a customer has several open invoices and
-
I m starting in SAP BW world, so one of the questions I got is how can I start my ELT activities with SAP BW??? Best Regards Joseph
-
Symptom: Sometimes, when you want to reinstall the Reporting Server Role for Operation Manager 2012, but you may encounter an issue that the Reporting Server Role cannot be reinstalled after you successfully uninstall it. When you check the System Ce
-
Error code 5103 when renting a movie
I get the following error message when I rented a movie from iTunes store, "An unknown error occurred (5103)". I downloaded the movie and when I tried to watch it, I got that message. I have tried disabling my firewall, reset iTunes cache, and restar
-
Estimate time usage for doing an P2V in VMM 2008 R2
Hi Is it possible to get a estimated time usage for doing a P2V in VMM 2008 R2? Maybe a preliminary scan or something? Lasse /Lasse