Convert lines to a single column
Hi allNeed help, I have a table where I want the output to a single column
ex: Select in t1. *
the query result_
rownum col_1
1 8217
2 6037
3-5368
4 5543
5 5232
I want the result to be: * 8217,6037,5368,5543,5232 *.
Thank you for your help in advance.
I search the web but couldn't find a solution that is easily understandable.
WM_CONCAT is not documented, so not everyone would want to use it in production code.
However, SYS_CONNECT_BY_PATH might work:
SQL> create table t as
2 select 1 rn, 8217 count_1 from dual union
3 select 2, 6037 from dual union
4 select 3, 5368 from dual union
5 select 4, 5543 from dual union
6 select 5, 5232 from dual;
Table created.
SQL> select * from t;
RN COUNT_1
--------- ----------
1 8217
2 6037
3 5368
4 5543
5 5232
5 rows selected.
SQL>
SQL> select rownum
2 , ltrim(sys_connect_by_path(count_1, ','), ',') count_1
3 from t
4 where connect_by_isleaf=1
5 start with t.rn=1
6 connect by t.rn = prior t.rn+1;
ROWNUM
-------
COUNT_1
-------------------------------------------------------------------------------------
1
8217,6037,5368,5543,5232
1 row selected.
Or LISTAGG on 11.2:
SQL> select listagg(count_1, ',') within group (order by rn) agged from t;
AGGED
-------------------------
8217,6037,5368,5543,5232
1 row selected.
I really hope that you do not really use ROWNUM as column name? I used instead RN...
Tags: Database
Similar Questions
-
Convert different lines in a single column
DB: 11.1.0.7
Operating system: Solaris Sparc 5.10
I have a query that is joining a few tables and give me output like below.
personnum orgnm
======= =======
The 6 key holder
9 sales
3 Mgmt
I would like to only convert a single as column below.
col1
========
6, keeper of the key, 9, sales, 3, Mgmt
I tried with pivot and decode, but not get out that I'm exepcting. Any suggesstions?yashwanth437 wrote:
listagg() function might work.LISTAGG is not available in 11.1. It was introduced in 11.2.
In any case, 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.
-
Convert the lines into a single column
create table suresh
(
Identification number,
ch char (1)
)
;
Insert in suresh values(1,'i');
Insert in suresh values(1,'a');
Insert in suresh values(1,'m');
Insert in suresh values(1,'b');
Insert in suresh values(1,'o');
Insert in suresh values(1,'y');
Select * from suresh
ID ch
1 I
1 a
1 m
1 b
1 o
1 y
I'm looking for output something like this
ID ch
1 iamboy
..select id,listagg(ch) within group(order by ch) as ch from suresh group by id
-
Create views of data from multiple lines in a single column shows
Hi all - it's probably posted in the wrong forum, but I couldn't find that was right.
I'm almost a perfect beginner in sql, but I have a need to create a view that can be expanded to 10g (which effectively runs the volumes are likely to be high) who will do the following.
Authentic table with columns Parent_code, Child_code
Parent_Code Child_Code
1000-2000
1000-3000
1000-4000
2000 3000
2000-5000
(note that Parents may have several children and a child can have multiple parents!)
What I have to finish with in my opinion is the following
Child_Code Parent_List
' 2000 ' 1000 (3).
3000 "1000 (3), 2000 (2)"
' 4000 ' 1000 (3).
"5000 ' 2000 (2)"
Note the number in parentheses is the number of children whose parent's - IE in the original parent a 1000, 3 table lines (one for each child)
This point of view should be used as a quick glance upward (on the children's code) for a report of business objects.
Is there someone who could you PLEASE, PLEASE help me quickly on what I have very little time to find a solution?Hello
You can test these:
select child_code , ltrim(sys_connect_by_path(parent_info,', '), ', ') as parent_list from ( select child_code , to_char(parent_code) || ' (' || count(*) over(partition by parent_code) || ')' as parent_info , row_number() over(partition by child_code order by parent_code) rn from your_table ) where connect_by_isleaf = 1 connect by prior rn = rn-1 and prior child_code = child_code start with rn = 1 ;
select child_code, rtrim( extract( xmlagg(xmlelement("e",parent_info||', ') order by parent_info) , '//text()' ) , ', ' ) as parent_list from ( select child_code, to_char(parent_code) || ' (' || count(*) over(partition by parent_code) || ')' as parent_info from your_table ) group by child_code ;
What you need is called 'chain aggregation '.
See here for the various techniques, including the two above: http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php -
Multiple lines in a single column in an SQL statement
Can someone provide me with a simple sql that runs on the underside of the table (USERROLE table)
ID ROLEUSER ROLENAME
1 user1 GL
User2 OBI_AP 2
User1 3 OBI_AP
User2 4 GL
User1 5 OBI_AR
User2 6 AR
7 the GL util_3
and give the result form
ROLENAMES ROLEUSER
User1 GL; OBI_AP; OBI_AR
User2 OBI_AP; GL; AR
the GL util_3
Thank you
VikramHello
There is a similar thread, you can watch: concatenate the values of column in a row
Kind regards
-
Need to concat lines to a single column
Hi all
Some examples of data.
col1 col2 col3
125 200 abc
126 200 def
127 200 IGS
128 210 homeless
129 rte 210
130 211 uiy
I need output like this.
col2 col3
200 abc, def, ghi
210 homeless, rte
uiy 211
I need data with order of col1
Could you please let me know how to build the query for this.
Thanks in advance.
Hello
Use the function of aggregation LISTAGG, like this:
SELECT col2
LISTAGG (col3, ",") THE Group (ORDER BY col1) AS col3_list,
FROM table_x
GROUP BY col2
;
This requires that you use Oracle 11.2 or greater.
The generic term for this is the String aggregation.
For more on the aggregation of the chain, including how to do this in earlier versions of Oracle, see ORACLE-BASE - String aggregation Techniques
-
Selection of Pixel single column, then paste...
Hello
This might look like a very unusual request, but I was upset to find the answer.
In a given photographic image, I would choose a single pixel in each row of pixels, running up and down in a columnof a pixel. Then, I want to eliminate (Cup) nothing else on the Web with the exception of the one column of selected pixels. From there, I would take the pixel selected in each line and copy the pixel color on each line on the left and right of the pixel selected.
The end result is that I have a series of horizontal lines of pixels height of one color (based on the color of the selected pixel) through the image of left and right.
Looking at this picture:
Select a single pixel on each line in a single column-
xxxxxx XXXXXXS
xxxxxx XXXXXXS
xxxxxx XXXXXXS
Remove/cut everything except the selected pixels in only one column-
...... S......
...... S......
...... S......
Now, on each line, copy single pixel selected to the left and the right of the selection, to the extent of the canvas-
SCOTTS SCOTT
SCOTTS SCOTT
SCOTTS SCOTT
Interesting challenge or Easy-Peasey?
Thank you!
Easy. Use the brand single pixel tool to select a line of pixels. Cmd/Ctrl-J to copy pixels into a new layer. CTRL/cmd-click on the layer icon to select these pixels. CTRL/cmd-T to turn those pixels on the width of the image.
-
value of multiple line in a single row (nclob)
Hello
I have a requirement where I have to work on a nclob data type column, now here the value of 2 lines in a single column. Like this:
Select extractvalue (xmltype (details), '/ Anything/invoiceNumber') separate as invoices,
actinguserid as user_id, createdt
of bchistevent where bucket = 201301
and upper (type) = ' COM. AVOLENT. PRESENTATION. EVENT. INVOICEDOWNLOADEVENT'
- and bchistevent.bucket = to_char (add_months (sysdate-1), "YYYYMM")
000-395452969-20130103 1.46388193452398E37 08/01/2013 03:05:42
300000590-000-20090723 1.46388193452398E37 11/01/2013 08:11:45
300000590-000-20090723 1.46388193452398E37 11/01/2013 08:12:50
000-395453127-20130103 1.46388193452398E37 14/01/2013 04:44:26
* 300084670-000-20120906, 300084671-000-20120906 * 1.46388193452398E37 07/01/2013 12:45:19 AM
000-395452626-20130103 1.46388193452398E37 08/01/2013 03:03:57
000-300084679-20120906-1.46388193452398E37 11/01/2013 08:10:47
300000728-000-20090731 1.46388193452398E37 11/01/2013 08:19:19
000-300084679-20120906 1.46388193452398E37 14/01/2013 12:31:48 AM
300000590-000-20090723 1.46388193452398E37 14/01/2013 04:13:19
000-395452718-20130103 1.46388193452398E37 08/01/2013 07:10:19
000-300084679-20120906 1.46388193452398E37 23/01/2013 06:54:11
000-300084679-20120906 1.46388193452398E37 22/01/2013 03:11:54
300000590-000-20090723 1.46388193452398E37 11/01/2013 08:14:02
000-395453127-20130103 1.46388193452398E37 14/01/2013 04:33:12
000-300084679-20120906 1.46388193452398E37 22/01/2013 03:03:36
000-300084679-20120906 1.46388193452398E37 14/01/2013 12:34:13 AM
000-395452997-20130103 1.46388193452398E37 07/01/2013 03:31:38
000-395452391-20121027 1.46388193452398E37 03/01/2013 04:40:05
and the value of the "BOLD" highlighted line is coming in a single line, please help how to break this in 2 rows?
Published by: user1175303 on March 13, 2013 05:43user1175303 wrote:
the value of the column that is involved is here I get 2 values in a single column, and for this reason, I am unable to get the desired result.300084670-000-20120906, 300084671-000-20120906 If you have XML question but try to solve in Oracle? Why
is the owner of two invoice numbers? In any case: with t as ( select distinct extractvalue(xmltype(details),'/Anything/invoiceNumber') as invoices, actinguserid as user_id, createdt from bchistevent where bucket = 201301 and upper(type) = 'COM.AVOLENT.PRESENTATION.EVENT.INVOICEDOWNLOADEVENT' ) select regexp_substr(invoices,'[^,]+',1,column_value) invoices, user_id, createdt from t, table( cast( multiset( select level from dual connect by level <= length(regexp_replace(invoices,'[^,]')) + 1 ) as sys.OdciNumberList ) ) /
SY.
-
Convert a single column into multiple lines
Hi people,
I have a task to display a single column into multiple lines (for use in LOV)
For Ex:
The column consistes of value such as 98,78,67,68,34,90. -It's a unique column values where none of the values can be ' number that is separated by commas
Then we must view it as
98
78
67
68
34
90
-under the number of lines (no lines can be ' do not number).
Thanks in advanceTry this...
SQL> ed Wrote file afiedt.buf 1 select regexp_substr('98,78,67,68,34,90', '[^,]+',1,level) Value 2 from dual 3* connect by level <= regexp_count('98,78,67,68,34,90',',') + 1 SQL> / VALUE ----------------- 98 78 67 68 34 90 6 rows selected.
Thank you!
-
convert a single column in lines
Hi gurus,
I have a GBA test table is id and name.
Identification number
name varchar2
data are like
name identity
1 xy
2 xyy
3 mm
4 pp
Now my requirement is to convert the IDs of unique column in lines
i, e my output should be Singel lines like:-1,2,3,4
How to achieve this result.
I have no idea to make this request.
Please help guys.
Thanks in advance.
VijayOh, wait, now I see:
I think that with clause will not work in this State
You have not the clause at all.
You can omit this part and change t in your own table name
I only used it to generate sample data.
That's why I commented :) - query real, based on the id is generated above: in the query, to indicate what is happening ;)As Alex has already pointed out:
You only need the part from the line 7 (first example) or line 10 (second example)Hands a great coffee to Alex
-
Single line based on two columns and a single column
Dear members,
I have a table that contains duplicate rows, for which a request should be able to extract the unique row in the table. Here the unique is not based on a single column, but it should be in two columns and also check on the uniqueness on a column.
create table addr (varchar2 (10) firstname, lastname varchar2 (10), area varchar2 (3));
insert into values addr ('bob', 'james', 1');
insert into values addr ('bob', 'james', 1');
insert into values addr ('harry', 'bert', ' 1');
insert into values addr ('jimmy', 'bert', ' 1');
insert into values addr ('sam', 'mac', '1');
insert into values addr ('sam', 'Knight', '1');
insert into values addr ('tom', 'sand', '1');
insert into values addr ("cat", "mud", "1");
The query output must contain 3 lines.
Bob - james
Harry - bert or jimmy - bert [or the other of them], but not both
-Mac or sam - Sam Knight [or the other of them], but not both
Tom - sand
Cat - mud
SELECT firstname, lastname as total area WHERE addr = '1' GROUP by firstname, lastname; It takes no duplication of single column...
Any suggestions...SQL> with t_data as ( select 'bob' as firstname, 'james' as lastname, '1' as area from dual union all select 'bob', 'james', '1' from dual union all select 'harry', 'bert', '1' from dual union all select 'jimmy', 'bert', '1' from dual union all select 'sam', 'mac', '1' from dual union all select 'sam', 'knight', '1' from dual union all select 'tom', 'sand', '1' from dual union all select 'cat', 'mud', '1' from dual ) SELECT firstname, lastname, area FROM ( SELECT t.*, row_number() over(partition BY firstname order by 1) rn, row_number() over(partition BY lastname order by 1) rn1 FROM t_data t ) WHERE rn = 1 AND rn1 =1 ; FIRSTNAME LASTNAME AREA --------------- --------------- ---------- bob james 1 cat mud 1 jimmy bert 1 sam knight 1 tom sand 1 SQL>
-
Convert multiple lines in a single value separated by commas
Is is possible to convert multiple lines in a single value by concatenating the value of each line in OBIEE. I think that IO had seem a blog related to this by I'm not able to find him. Essentially, here's what I would do:
Number of customer location
101
101 NY
101 PA
102 TX
102 CA
This is to convert
101. HE, NY, PA
102 TX, CA
Can you get it someone please let me know if this is possible and how to operate it.
Thanks in advance for the help.You can do this by creating a DB function,
Visit this link
Re: Display of the horizontal valuesThank you
Vino -
View all in a single column, instead of lines (part 1)
Hi all
Help, please...
I have a table: EMP & 3 columns: ID, ENAME, and BIRTHDAY.How to make my lines of output SQL to display on a single column?
I inserted 3 rows in the table:
ID ENAME BIRTHDAY
1 Smith 11/09/1980
2 Jones 01/01/1981
3 Baker 02/02/1982
EmployeesI want the output of my query in Oracle Developer / ApEx to display like this:
---------------
Smith
11/09/1980
Jones
01/01/1981
Baker
02/02/1982
Best regards
Sunenny
Published by: user643233 on November 6, 2008 09:10Strange formatting. Maybe you could try something like this...
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production SQL> CREATE OR REPLACE TYPE varchar2_table AS TABLE OF VARCHAR2 (4000); 2 / Type created. SQL> SELECT column_value 2 FROM emps, TABLE (varchar2_table (NULL, ename, hiredate)); COLUMN_VALUE -------------------------------------------------------------------------------- SMITH 17-DEC-80 ALLEN 20-FEB-81 WARD 22-FEB-81 JONES 02-APR-81 MARTIN 28-SEP-81 BLAKE 01-MAY-81 CLARK 09-JUN-81 SCOTT 19-APR-87 KING 17-NOV-81 TURNER 08-SEP-81 ADAMS 23-MAY-87 JAMES 03-DEC-81 FORD 03-DEC-81 MILLER 23-JAN-82 42 rows selected. SQL>
-
Remove the clicked point of Listbox (single column)
Hello
It seems a lot of posts on clear lines of the programmatically multicolumn listbox but not the only column listboxes.
Woth the help of Martins and GerdW, helped me build a subset of a ListBox with items clicked in a reference list
Make a table of items clicked in a list
. How it adds a feature to delete just in case rather than the deletion of the entire list and do it all over again.
Thanks in advance.
Have an array of strings to the "REF" enter in the list box and store it on a shift register. When you remove an item (for example, for an event), remove this item from the list (using the removal of the table) and write back to the property Ref of the listbox. A single-column list box works exactly the same way as a multicolumn listbox.
(Excuse the broken links to properties - what happens when you create an excerpt)
-
Hello
I need to split into single column in the format below:
SELECT '6500,1100,3200,1233,9000' FROM DUAL;
Result:
6500
1100
3200
1233
9000
For 11g and above:
Select regexp_substr (6500, 1100, 3200, 1233, 9000', ' [^,] +', 1, level) suite
of the double
connect by level<= regexp_count('6500,1100,3200,1233,9000',="" ',')="" +="">=>
For 10g:
Select regexp_substr (6500, 1100, 3200, 1233, 9000', ' [^,] +', 1, level) suite
of the double
connect by level<= length="" (regexp_replace="" ('6500,1100,3200,1233,9000',="" '[^,]+'))="" +="">=>
or (if there is no empty entries):
Select regexp_substr (6500, 1100, 3200, 1233, 9000', ' [^,] +', 1, level) suite
of the double
connect regexp_substr (6500, 1100, 3200, 1233, 9000', ' [^,] +', 1, level) is not null
RESULT 6500 1100 3200 1233 9000 5 selected lines.
Maybe you are looking for
-
I have a job in the compressor that is stuck and not move not. I can add more files to process, and they code OK. I tried to restart the Mac and still isn't the problem. I'm sure that several years ago I had this but can't remember how to solve. This
-
Question about Toshiba update alert
Hello everyone. First of all, I'll give you my configuration: Toshiba Satellite P200.(I hope that's enough?) And now my problem: I noticed that the utility tool alert Toshiba (I don't remember the good reputation. It is the tool that warn you when th
-
Satellite L300 - Built In webcam suddenly stopped working
Hello I have a Toshiba Satellite L300 with a built-in USB 2.0 camera and a windows operating system 7, the camera suddenly stopped working for about 2-3 weeks ago with unknown reason! I tried the system restore, uninstall and reinstall the camera dri
-
How to install Windows Xp on Satellite L300D?
I have Satellite L300D - 13s /PSLC8E with Win Vista Home Premium and I try to install Windows XP from boot and nothing.Error all the time. I try a few versions of XP anyway.How to expel C format Vista? Any advice?
-
EX7000 with USB 3.0 Hub
The EX7000 (Extender/Access Point) has a USB 3.0 port. Can I use ReadyShare installation with a USB and USB printer simultaneously by connecting a USB 3.0 hub to the EX7000?