Concatenate Multiple Columns into Single
Hi All,
I am developing a report and there is a field called FUNDING_SOURCE.
This field is being picked from class_code of PA_PROJECT_CLASSES table as shown below:
(select distinct(class_code)
from pa_project_classes ppc,
pa_projects_all ppa
where class_category = 'FUNDING SOURCE'
and ppc.project_id = :project_id)
But, the requirement is to have all values of Funding Source for a particular project ID concatenated into a single column.
Eg: If I run the above code, the output would be in 3 rows,
Intenal
External
Other
I want the output concatenated and displayed as Internal, External, Other.
Please help me ASAP. Need to finish this soon.
Thanks!
SELECT substr(MAX(sys_connect_by_path(a,
'~')),
2) --first character wil be ~ max is used because the query will return 3 rows and u need only one row with all values appended
FROM (SELECT a,
row_number() over(ORDER BY t.b) AS curr, --order in which appending happens
row_number() over(ORDER BY t.b) - 1 AS prev --order in which appending happens
FROM (SELECT 'Internal' a,
1 b
FROM dual
UNION ALL
SELECT 'External' a,
2 b
FROM dual
UNION ALL
SELECT 'Other' a,
3 b
FROM dual) t --creating dummy table
CONNECT BY prev = PRIOR curr
START WITH curr = 1;
Similar Messages
-
Concatenate multiple columns into one string
Hello,
I am using Oracle 11.2, how can I concatenate the value of multiple columns into one string with one SQL:
create table testTb(classId number(5), classRoom varchar2(32));
insert into testTb value(101, 'room101');
insert into testTb value(101, 'room201');
insert into testTb value(101, 'room301');
insert into testTb value(202, 'room444');
insert into testTb value(202, 'room555');
I would like to generate the result as followings:
Class 101 is in room101, room201, room301
Class 202 is in room444, room555
Thanks,Hi,
Since you're using Oracle 11.2, you can use the aggregate LISTAGG function:
SELECT 'Class ' || classid
|| ' is in '
|| LISTAGG ( classroom
) WITHIN GROUP (ORDER BY classroom)
AS txt
FROM testtb
GROUP BY classid
;The generic name for concatenating all the strings in a group is String Aggregation . This page shows several ways to do it, suitable for different versions of Oracle. -
Merge multiple columns into single column?
Hi,
I need to execute queries dynamically and return the values. I need to fetch the values of the queries in single column only by concatenating the multiple columns. I cannot use PL/SQL in my scenario.
is there any way to execute a query and the result will be fetched in single column (values of multiple columns needs to be concatenated)?
Thanks,
Raja.hi,
do you mean this??
1* select EMPNO||' '||ENAME||' '||JOB||' '||MGR||' '||HIREDATE||' '||SAL||' '||COMM||' '||DEPTNO||
SQL> /
MULTIPLE_COL
100 JDF DIR 05-SEP-09 200 1000 10
7497 MILLER CLERK 7782 23-JAN-82 25000 195 35
7566 JONES MANAGER 7839 02-APR-81 3175 446.25 20
7654 RAR SALESMAN 7698 28-SEP-81 1450 1587.5 30
7698 BLAKE MANAGER 7839 01-MAY-81 3050 427.5 30
7782 CLARK MANAGER 7839 09-JUN-81 2650 367.5 10
7788 SCOTT ANALYST 7566 09-DEC-82 3200 450 20
7839 KING PRESIDENT 17-NOV-81 5200 8250 10
7844 TURNER SALESMAN 7698 08-SEP-81 1700 225 30
7876 ADAMS CLERK 7788 12-JAN-83 1300 165 20
7900 JAMES CLERK 7698 03-DEC-81 1150 85.5 30 [email protected]
MULTIPLE_COL
7902 FORD ANALYST 7566 03-DEC-81 3200 450 20
8000 KINGBABA PRESIDENT 17-NOV-81 5200 8250 10
8001 TURNER RAV SALESMAN 8000 08-SEP-81 1700 450 30
1001 KITTU DOR 05-SEP-09 1200 100 40
15 rows selected.Or
Mean this??
SQL> ed
Wrote file afiedt.buf
1 With T As
2 ( Select Level col1 From dual Connect By Level<=10
3 )
4 Select Max(SYS_CONNECT_BY_PATH(COL1||',',' ')) Multi_col
5 From
6 ( Select COL1, Lag(COL1) Over (Order By COL1) As Lag
7 From T )
8 Start With Lag Is Null
9 Connect By
10* Prior col1 = LAG
SQL> /
MULTI_COL
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,Edited by: user291283 on Sep 8, 2009 10:10 PM -
Transform Multiple column into single column;
Hi all,
I have a table with multiple columns
Col_1
Col_2
Col1_3
Col_4
Col_5
Col1_6
Col_7
Col_8
Col1_9
Val_1
val_2
Val_3
Val_4
val_5
Val_6
Val_7
val_8
Val_9
Oper1
Oper2
Oper9
Currently the table look like this
ID Name | f_actve | Col_1| Col_2|….Col1_9| Val_1| val_2| …Val_9| Oper1…..| Oper9
Now I need to insert the data into new table The structure of the new table look like this
Table : T1 (header)
ID | Name | F_active
Table : T2 (detail )
Dtl ID | Columnname | Oper
Now all the column_name Col_1through Col_9 should be inserted into column_name column.
Same thing with the Opers
Table T3(detail )
DTL_ID | Column_Values
Now all the Column_Values Col_1through Col_9 should be inserted into column_name column
Please help
We have 10G /11g.
Thanks
RebeccaWhat you are trying to do is called unpivot in 11g.
See this example.
SQL> WITH T
2 AS (SELECT 1 dtl_id,
3 1 col1,
4 2 col2,
5 3 col3,
6 4 col4
7 FROM DUAL)
8 SELECT * FROM T;
DTL_ID COL1 COL2 COL3 COL4
1 1 2 3 4
SQL> WITH T
2 AS (SELECT 1 dtl_id,
3 1 col1,
4 2 col2,
5 3 col3,
6 4 col4
7 FROM DUAL)
8 SELECT dtl_id, "COL_VALUES"
9 FROM T UNPIVOT (col_values FOR abc IN (col1, col2, col3, col4));
DTL_ID COL_VALUES
1 1
1 2
1 3
1 4
SQL> -
Concatenate multiple rows into single row
Hi I need to concatenate multiple rows,
these are the rows I have
Name
Rnk
Northshore
1
F3
2
Borderline
3
Mattoon
3
Vinemane
5
Arizona
5
WestShore
5
Schumburg
5
Wilson
5
This is how I would like it to look
Name
Rnk
Northshore
1
F3
2
Borderline, Mattoon
3
Vinemane, Arizona, WestShore, Schumburg, Wilson
5
Thanks
LISA86I meant is there a way to do it without using a table?
LISA86
We have not used any extra table. Ok, Try the below:
Select distinct
names= REPLACE(
Select a.Name as [data()]
From YOURTABLENAME A
Where A.Rnk = b.Rnk
Order by a.Name
FOR XML PATH ('') ), ' ', ',') ,Rnk
From YOURTABLENAME B Order by Rnk -
Concatenate multiple records into one single record
Hello everyone,
Can anyone guide me how to merge multiple records into one single record
like......... I am getting the data in the file like
aaaaa/bbbbbbb/ccccccccccc/dddddddddddd/eee
ffffff/gggg/hhhhhhhhhhhhhh
/123/4567/55555/99999999/kaoabfa/eee
fffff/kkkkkkkk/llllllllllllllllllllllll
when i use gui_upload I am getting the data into the internal table in the above format.
My main intension is to split the record at / to multiple lines and dowload it into another file.
What i am planning to do is... if the line does not start with / then i want to concatenate the multiple lines into single line and then split it into multiple records. Can anyone guide me how to achieve this.Yes, it should work.
In my example
Loop at itab.
concatenate i_text itab into i_text.
endloop.
You change that loop for the loop of your internal table with the file records
So if you have this three records
'aaaa/bbb/ccc'
'/dddd/efg'
'hijk/lmn'
i_text will look like this at the end
'aaaa/bbb/ccc/dddd/efghijk/lmn'
then in this part of the code
split i_text at '/' into table itab2.
itab2 will have the records looking like this
aaaa
bbb
ccc
dddd
efghijk
lmn' -
Displaying data from multiple columns into a single line graph
Post Author: hollowmatrix
CA Forum: WebIntelligence Reporting
Hey,I have an issue with the WEBI reporting.I have a data source that has multiple columns say ( month1, month2, month3, month4,.....month 12, month 13, ....month24) with the sales data for each month.Now say I call the month 1 to month 12 as "current year", and call month 13 - month 24 as "previous year".I want to put a prompt in the report which allows me to select between "current year" and "previous year".Based on the prompt value we get a graph of the sales vs month ....as in if we select "current year", then we get a graph of the sales Vs time( remember that the sales data for each month is in a different column.)and if we select "previous year" then we get a graph of the sales Vs time for previous year..( sales vs time for Month 13, month 14, month 15....month 24).I am not able to pull data from multiple columns into a single object that I can use to populate the graphs.Any help on the same will be appreciated .Hi,
<p>
please click
here (asktom) and look for the words "how about the other way round"
</p> -
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} -
Scanning multiple pages into single document
Is there a way to scan multiple pages into single document? I am using the following: HP pavilion laptop with windows 8, HP photosmart C6380 all in one printer scanner copier.
Hi,
Please try
Double click printer icon on desktop,
Select Scan a Document or Photo,
Put the first page on the glass (face down),
Check options (size, dpi ...), and select Scan document to file,
Click Scan - machine will scan the first page
Remove the first page on the glass, put the second page,
Click + (plus sign) It sits on the left hand side of a red x
Machine will scan the second page, put 3rd page on the glass and click + again ..... to the end then click Save
Click Done after Save
Regards.
BH
**Click the KUDOS thumb up on the left to say 'Thanks'**
Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem. -
How to Pass multiple parameter into single store procedure
How to Pass multiple parameter into single store procedure
like a one to many relationship.
it is possible then reply me immediatlyyou mean like this .....
CREATE OR REPLACE procedure display_me(in_param in varchar2,in_default in varchar2 := 'Default') is
BEGIN
DBMS_OUTPUT.put_line ('Values is .....'||in_param || '....'||in_default);
END display_me;
CREATE OR REPLACE procedure display_me_2 as
cnt integer :=0;
BEGIN
For c1_rec In (SELECT empno,deptno FROM test_emp) Loop
display_me(in_param => c1_rec.empno);
cnt := cnt+1;
end loop;
DBMS_OUTPUT.put_line('Total record count is ....'||cnt);
END display_me_2;
SQL > exec display_me_2
Values is .....9999....Default
Values is .....4567....Default
Values is .....2345....Default
Values is .....7369....Default
Values is .....7499....Default
Values is .....7521....Default
Values is .....7566....Default
Values is .....7654....Default
Values is .....7698....Default
Values is .....7782....Default
Values is .....7788....Default
Values is .....7839....Default
Values is .....7844....Default
Values is .....7876....Default
Values is .....7900....Default
Values is .....7902....Default
Values is .....7934....Default
Values is .....1234....Default
Total record count is ....18 -
How to convert single column into single row
I need to convert single column into single row having n no.of.values in a column. without using case or decode. I need a query to display as below.
emp_id
100
101
102
102
103
200
I need output like 100,101,102,103,104.........200.I assume you want to convert 200 rows with one column into one row with 200 columns. If so, this is called pivot. If you know number of rows (max possible number of rows) and you are on 11G you can use PIVOT operator (on lower versions GROUP BY + CASE). Otherwise, if row number isn't known, you can use dynamic SQL or assemble select on clent side. Below is example emp_id = 1,2,..5 (to give you idea) and you are on 11G:
with emp as (
select level emp_id
from dual
connect by level <= 5
select *
from emp
pivot(
max(emp_id) for emp_id in (1 emp_id1,2 emp_id2,3 emp_id3,4 emp_id4,5 emp_id5)
EMP_ID1 EMP_ID2 EMP_ID3 EMP_ID4 EMP_ID5
1 2 3 4 5
SQL>
SY. -
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 -
Converting multiple columns into one.
All,
I have a requirement to convert multiple columns into one. Following is the pseudo code of current implementation. It unions the various columns ( col1, col2........) into a new column new_col. But perforamnce is extrmely slow owing to multiple unions. It may be noted that tables and where conditions of all these queries are same.
Can you help me create a more efficient query?
select col1 , col2, col3, col4 from my_tables where some_cols = my_condition;Below is the query used to convert these columns into one.
select col1 new_col from my_tables where some_cols = my_condition
union all
select col2 from my_tables where some_cols = my_condition
union all
select col3 from my_tables where some_cols = my_condition
union all
select col4 from my_tables where some_cols = my_conditionWithout looking at those things you could be barking up the wrong tree by assuming the issue relates to the unioning of queries or other such things.Well, might be.........
Execution time of this query (just the execution time not the retrival) is around 34 seconds with connect-by clause for returning 22,000 records.
Here's the plan
Execution Plan
| Id | Operation | Name | Rows
| Bytes | Cost (%CPU)|
| 0 | SELECT STATEMENT | | 326
| 33904 | 135 (2)|
| 1 | SORT ORDER BY | | 326
| 33904 | 135 (2)|
| 2 | MAT_VIEW ACCESS BY INDEX ROWID | MV_COMQ_RM_DEAL | 1
| 62 | 1 (0)|
| 3 | NESTED LOOPS | | 326
| 33904 | 134 (1)|
| 4 | MERGE JOIN CARTESIAN | | 326
| 13692 | 3 (0)|
| 5 | VIEW | | 1
| 13 | 2 (0)|
| 6 | COUNT | |
| | |
| 7 | CONNECT BY WITHOUT FILTERING| |
| | |
| 8 | FAST DUAL | | 1
| | 2 (0)|
| 9 | BUFFER SORT | | 326
| 9454 | 3 (0)|
| 10 | TABLE ACCESS BY INDEX ROWID | SF_SEARCH_IDS_TMP_COMQ | 326
| 9454 | 1 (0)|
| 11 | INDEX RANGE SCAN | IDX1_SF_SEARCH_IDS_TMP_COMQ | 349
| | 1 (0)|
| 12 | INDEX RANGE SCAN | IDX_MV_COMQ_RM_DEAL | 9
| | 1 (0)|
----------------------- Hope, It's readable.......
I would have posted sample data and query but........I cant do that...:( -
How can i import the data from multiple sources into single rpd in obiee11g
how can i import the data from multiple sources into single rpd in obiee11g
Hi,
to import from multiple data sources, first configure ODBC connections for respective data sources. then you can import data from multiple data sources. When you import the data, a connection pool will create automatically.
tnx -
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>
Maybe you are looking for
-
Add profit center in report painter
Hi to all, I I have a small requirement in FICO.We added a one profit center in one report in FGI5 tcode.Is it enough for that report or anything to add to this report , i.e is there any modifications in coding or can i proceed with the tran
-
Can't load properties from file in webapp
I've got a bean that I use to read a properties file. from the JSP page, I use <%@ page import="com.buildrequest.Login" %> <jsp:useBean id="buildproperties" scope="page" class="com.buildrequest.BuildProperties" /> <jsp:setProperty name="buildproperti
-
Where is my table,if Package is not given for RPY_TABLE_INSERT?
Hi, I have a question on FMs RPY_TABLE_INSERT and DDIF_TABL_PUT. When the RPY_TABLE_INSERT is called ,a dialog is poped up to give package name and so on.If I don't select any package or I click 'Cancel' in this dialog,then use DDIF_TABL_PUT to wri
-
Apach 2.2.21 using Weblogic Plugin (10.3.5)
Hi All, I have configure apache using Weblogic Plugin and it work for http. So moving forward, i am trying to configure a 2 way SSL with weblogic plugin and have configure all the oracle wallet. I got my plugin from my weblogic server /opt/bea/wlserv
-
Burn a mp3 disk with acc files
I have a library full of ACC (mp4) files. In the old days I have chosen mp3 as my iTunes format but seduced by soundquality/filesize I converted all my CDs to ACC again. Now...i recently bought a mp3 capable cd player for the car. In the old days I c