Concat different rows column into single row field
Hi,
I have a table tblSite which has SiteID and SiteInvestigator. Can I concat different row base on siteID.
SiteID -- SiteInvestigator
1 -- x
1 -- y
2 -- z
2 -- x1
3 -- x2
Basicaly I want data look like this,
sitid --siteinvestigator
1 -- x,y
2 -- z,x1
3 -- x2
I want to use only sql query or create a view to get data like this. No stored procedure please.
Can somebody help?
Regards,
Vinay
this example might be of help.
SQL> select * from tab1;
COL1 COL2 COL3 COL4
Sofinummer 1 occupation 1
Sofinummer 1 occupation 2
Sofinummer 1 occupation 3
Sofinummer 2 occupation 1
SQL> select col1, col2,
2 substr(replace(max(substr(sys_connect_by_path (col3||' '||
3 col4, '-'),2)),'-',' '),1,60)
4 as col3
5 from tab1
6 start with col4 = 1
7 connect by col4 = prior col4 + 1
8 and prior col1 = col1
9 and prior col2 = col2
10 group by col1, col2;
COL1 COL2 COL3
Sofinummer 1 occupation 1 occupation 2 occupation 3
Sofinummer 2 occupation 1
SQL>
Similar Messages
-
Store values of different data types into single database field
Hi Friends,
I have to store values of different data types(character, numeric, date, time, text, etc) into a single database field(Char 80). Then read the same values and display it into ABAP Webdynpro report.
Appreciate any ideas, examples, suggestions.
Thanks
JBHi,
Try like this:
data: txt1 type string,
var1(1) type c,
var2(1) type n,
var3 like sy-datum,
var4 like sy-uzeit.
parameters: a type c,
b type n,
c like sy-datum,
d like sy-uzeit.
concatenate a b c d into txt1.
write txt1.
var1 = txt1+0(1).
var2 = txt1+1(1).
var3 = txt1+2(8).
var4 = txt1+8(8).
write: / var1,
/ var2,
/ var3,
/ var4.
Regards,
Bhaskar -
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. -
Total XML structure into single table field
Hello All,
I want to send total XML structure(including Tags and Data) into single field in a Table.
Ex: <MaterialDetails>
<MaterialNumber>00111</MaterialNumber>
<MaterialQuantity>200</MaterialQuantity>
</MaterialDetails>
Plz Can anyone tell me How to do this indetail?
Thanks
SanGenerate this entire string in a UDF and assign it to the respective element.
VJ -
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; -
Merging values of CKFs in two columns into single column
Hi ,
I want to merge values present in two different columns.The values present in rows of one column are not present in rows of other column, I have to merge the values into a single column.so that in the single column i can get all the values.how to do it in BEx.
regards ,
man.Hi,
Dear murali , the solution you gave has helped me a bit as i am able to get the values for both the formula KF's in the same column,But another problem has arisen.
For both the formula KF's I had to choose 'New Selection' (and not 'New formula')after R-cllick on the structure, as I had to use a Characteristic as restriction for Each of the KF's, and also to use the Characteristic I had to associate it with some KF so that the Characteristic wil be used as a KF in the formula.
Now what is happening is that I am getting the values of that associated KF also in the empty rows.(i.e. the rows where the value of both the KF1 and KF2 is not present)
What has to be done to remove them and keep the empty rows empty and not show the value of the KF taken with the Characteristic for restriction. Also its value is summing up with KF1 and KF2 in the coulmn which is having both KF1 and KF2 together.
Regards
man -
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> -
Combine 2 different list columns and showning in 1 column
Hi,
Is it possible to combine columns of 2 different lists and show in one column?
I have a custom list called "Levels" which contain data like "Developer", "Tester". The levels have some training associated. Training is another column.
I have another custom list called "Project", which contain "project name" and also some training for each project. Training is another column.
I have another list in which i have user names which contain the level and project name columns as look up.
I want to show all the trainings attached to the user in another list in a single column.
Example: If user is a developer and part of project A, then column named training should show all the developer training and the project related training.
Note: custom coding is not possible.
How to achieve this?
ThanksHi,
For your issue, you can combine 2 different list columns into one cloumn using SharePoint Desinger Workflow with update list item action:
Best Regards,
Eric
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Convert different rows into single column
DB : 11.1.0.7
OS : Solaris Sparc 5.10
I have one query which is joining few tables and giving me output like below.
personnum orgnm
======= =======
6 Keyholder
9 Sales
3 Mgmt
I would like to convert that into single column like below.
col1
========
6,Keyholder,9,Sales,3,Mgmt
I have tried with pivot and decode, but not getting resule which I am exepcting. Any suggesstions ?yashwanth437 wrote:
listagg() function could work.LISTAGG is not available in 11.1. It was introduced in 11.2.
Anyway, XML solution:
with sample_table as (
select 6 personnum,'Keyholder' orgnm from dual union all
select 9,'Sales' from dual union all
select 3,'Mgmt' from dual
select rtrim(xmlagg(xmlelement(e,personnum || ',' || orgnm,',').extract('//text()')),',') col1
from sample_table
COL1
6,Keyholder,9,Sales,3,Mgmt
SQL> SY. -
Concatenate strings from a column into a single row
I am trying to string values from a column into a single row. I need a list of students (one row per student) with their phone number and they could have more than one number. I found a function that should do what I need but the syntax is for SQL Server, not SQL*Plus. I've tried several variations but can not come up with the correct syntax.
This is the SQL Server version:
CREATE FUNCTION dbo.GetPhoneList(@StudentID int)
RETURNS varchar(500) AS
BEGIN
DECLARE @StringList varchar(500)
SELECT @StringList = COALESCE(@StringList + ‘, ‘, ”) + Telephone.PhoneNumber
FROM Telephone t
WHERE t.StudentID = @StudentID
IF @StringList IS NULL
SET @StringList = ‘No Phone’
RETURN @StringList
END
SQL*Plus does not like the @ symbol, so I tried taking that out. I've put semi-colons where I think they should be, but I still get various error messages. Any suggestions?
Thanks.Hi,
What you want to do is called "String Aggregation"
You could write a PL/SQL funcrtion to do that for a specific column in a specific table, but [this page|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2196162600402] has a couple of different generic solutions that will work on any tables and columns.
I recommend the first soluton, the user-defined function STRAGG, which you can copy from that page.
Once you have STRAGG installed, your query can be something like:
SELECT s.student_id
, NVL ( STRAGG (t.phone_number)
, 'No phone'
) AS phone_nums
FROM student s
LEFT OUTER JOIN telephone t ON s.student_id = t.student_id
GROUP BY s.student_id;On Oracle 10 (and up) you may have a similar function, WM_CONCAT (owned by WMSYS), already installed.
WM_CONCAT is not documented, so you may not want to use it in your Production applications.
It lokks like
Edited by: Frank Kulash on Feb 10, 2009 6:31 PM -
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} -
thx guys.....i have a progress now in LV
But now i have new trouble here. Ok i attached my LV file (LV 7.0.1/7.1) and excel form. I just could'nt calculate more than one input value. I want a different result for each value that i enter ... and store it into different rows and column. But it just store at one row.
Attachments:
My Project.vi 31 KB
rumus motor bakar.xls 14 KBduplicate post
-
Converting multiple column rows into single column
Hi all Below is my requirement, can you anybody help me solve it. CREATE TABLE TYPE ( c1_type VARCHAR2 (10), c2_type VARCHAR2 (10), c3_type VARCHAR2 (10), c4_type VARCHAR2 (10), c5_type VARCHAR2 (10), c6_type VARCHAR2 (10), c7_type VARCHAR2 (10), c8_type VARCHAR2 (10), c9_type VARCHAR2 (10)); INSERT INTO TYPE VALUES ('Region_D', 'Region_E', 'Region_F', 'Region_D', 'Region_E', 'Region_D', 'Region_M', 'Region_D', 'Region_E'); commit; Acutal output on the below query select * from type; C1_TYPE C2_TYPE C3_TYPE C4_TYPE C5_TYPE C6_TYPE C7_TYPE C8_TYPE C9_TYPE Region_D Region_E Region_F Region_D Region_E Region_D Region_M Region_D Region_E Acutal i am expecting the below output,how to make it using query or using oracle built in function. Region_D Region_D Region_D Region_D Region_E Region_E Region_E Region_F Region_M
Hi,
So, you want to put the column values in alphabetic order, with the earliest value in c1_type and the last in c9_type, is that it?
The fact that you even want to do this says that this is a bad table design. If sorting the values makes sense, then putting them all in the same column on 9 different rows (rather than 9 different columns on 1 row) makes sense.
If you're stuck with the current design, then use SELECT ... UNPIVOT to put them on separate rows, then use the analytic ROW_NUMBER function to assign numbers 1-9 to each value, and finally use SELECT ... PIVOT to put them back into 1 row in that order. If you're not familiar with the built-in UNPIVOT and PIVOT features, look them up in the SQL Language manual, and see the forum FAQ:
https://forums.oracle.com/message/9362005
If you get stuck, post your best attempt (formatted), the exact results you want (formatted), and your Oracle version (e.g. 11.2.0.2.0).
Also, TYPE is an Oracle keyword, so it's not a good table name. Use something like location_type instead. -
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
-
USB 2.0 Hubs hooked to iMac G5 can't seem to sustain devices ...
about a month ago I noticed that my iPod and iPhone would occasionally disappear from my Device list in iTunes while plugged in. Both were connected to my computer via USB slots on my NewerTech miniStack v2. I plugged various devices into the USB slo
-
How do I completely remove itunes from my computer so I can reinstall it?
After I did the update I keep getting this message that pops up when I open itunes "The file 'itunes Library.itl' does not appear to be a valid itunes library file. iTunes has attempted to recover your itunes library and renamed this file to 'iTunes
-
In-Browser Elevated Permissions Setup with SL5 Issues
I am having a devil of a time setting up in-browser elevation with an application I'm developing for a client. Software's purpose: Download excel, docx and other writable files to a user's system, launch the file in the default viewer, let the user e
-
Replicating MS Access single form record selectors functionality
I am very new to APEX. I would like to rebuild and improve on all our departments MS Access userforms using APEX. At the moment I am trying to replicate the standard MS Access "single form" view of a record in a database table, with the record select
-
Is there a problem for the iphone 4 if there is a power cut, while charging it up?
Does it damage the iphone 4 or something? Help me please :S