Comma separated output into columns
Hi,
I've the following Query :
select ParameterValue
FROM Event.vEvent
join event.vEventParameter on event.vEventParameter.EventOriginId=event.vEvent.EventOriginId
where EventNumber=0
which gives the following output in a single column:
VSSDATA_FS,171423,106013,142420,11,248433,Wed Jun 4 03:40:58 EDT 2014
DATAGRP_FS,2302724,1074283,2208370,39,3282653,Wed Jun 4 07:54:26 EDT 2014
DATAPUB_FS,100837,5998,36688,49,42686,Wed Jun 4 03:04:42 EDT 2014
SHT_APT_FS,1008350,651,3906,84,4557,Mon Jun 2 03:12:35 EDT 2014
SHT_GER_FS,806699,809987,747788,52,1557775,Thu Jun 5 03:55:33 EDT 2014
DATAGRP1_FS,151256,24805,120496,33,145301,Tue Jun 3 05:11:31 EDT 2014
I need to separate the above output in different columns using separators as ',' (comma).
Please help me in achieving this as I'm a newbie in SQL.
pass it through a parameter
DECLARE @p varchar(max) = 'VSSDATA_FS,171423,106013,142420,11,248433,Wed Jun 4 03:40:58 EDT 2014
DATAGRP_FS,2302724,1074283,2208370,39,3282653,Wed Jun 4 07:54:26 EDT 2014
DATAPUB_FS,100837,5998,36688,49,42686,Wed Jun 4 03:04:42 EDT 2014
SHT_APT_FS,1008350,651,3906,84,4557,Mon Jun 2 03:12:35 EDT 2014
SHT_GER_FS,806699,809987,747788,52,1557775,Thu Jun 5 03:55:33 EDT 2014
DATAGRP1_FS,151256,24805,120496,33,145301,Tue Jun 3 05:11:31 EDT 2014'
SELECT Val
FROM dbo.ParseValues(@p,',')
ParseValues can be found here
http://visakhm.blogspot.in/2010/02/parsing-delimited-string.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Similar Messages
-
Inserting the Comma Separated Strings into Table
Hi Seniors,
i had two string and i want to insert the records in the Table COMMENT . In this way.
would u please give some programe to insert the records.
The Data and the Table
( 901,902,903,904 )
( 'hai','nice','good & mail is [email protected] ','excellent and the phone 011-235323' )
comm_id loc_id company_name comments
1 10 901 Hai
2 10 902 nice
3 10 903 good & mail is [email protected]
4 10 904 excellent and the phone 011-235323
Thanks
SeenuHi, Seenu,
In Oracle 10 (and up) you can easily split a comma-delimited list using REGEXP_SUBSTR.
INSTR and SUBSTR can do the same thing in any version, but it's more complicated.
See the general instructions below:
/* How to Split a Delimited String
This shows how to take a single row with a delimited string, such as
Animal amoeba,bat,cedusa,dodo
and transform it into multiple rows:
Animal 1 amoeba
Animal 2 bat
Animal 3 cedusa
Animal 4 dodo
PROMPT ========== -1. sep_char parameter ==========
VARIABLE sep_char VARCHAR2 (10)
EXECUTE :sep_char := ',';
SELECT :sep_char AS sep_char
FROM dual;
PROMPT ========== 0. string_test table ==========
DROP TABLE string_test;
CREATE TABLE string_test
( grp_name VARCHAR2 (10)
, list_txt VARCHAR2 (50)
INSERT INTO string_test (grp_name, list_txt) VALUES ('Animal', 'amoeba,bat,cedusa,dodo');
INSERT INTO string_test (grp_name, list_txt) VALUES ('Date', '15-Oct-1582,16-Oct-2008');
INSERT INTO string_test (grp_name, list_txt) VALUES ('Nothing', NULL);
INSERT INTO string_test (grp_name, list_txt) VALUES ('Place', 'New York');
INSERT INTO string_test (grp_name, list_txt) VALUES ('Skip', 'Hop,,Jump');
SELECT *
FROM string_test
ORDER BY grp_name;
PROMPT ========== Q1. Oracle 11 Query ==========
WITH cntr AS -- Requires Oracle 9
( -- Begin sub-query cntr, to generate n (1, 2, 3, ...)
SELECT LEVEL AS n -- Requires Oracle 9
FROM dual
CONNECT BY LEVEL <= 1 + (
SELECT MAX ( REGEXP_COUNT (list_txt, :sep_char) ) -- Requires Oracle 11
FROM string_test
) -- End sub-query cntr, to generate n (1, 2, 3, ...)
SELECT grp_name
, n
, REGEXP_SUBSTR ( list_txt -- Requires Oracle 10
, '[^' || :sep_char || ']' -- Anything except sep_char ...
|| '+' -- ... one or more times
, 1
, n
) AS item_txt
FROM string_test
JOIN cntr -- Requires Oracle 9
ON n <= 1 + REGEXP_COUNT (list_txt, :sep_char) -- Requires Oracle 11
ORDER BY grp_name
, n;
/* Notes:
REGEXP_SUBSTR (s, '[^,]+', 1, n)
returns the n-th item in a comma-delimited list s.
If there are fewer than n items, it returns NULL.
One or more consecutive characters other than comma make an item, so
'Hop,,Jump' has two items, the second one being 'Jump'.
The sub-query cntr produces a list of integers 1, 2, 3, ..., w
where w is the worst-case (the largest number of items in any list).
This actually counts separators, not items, (e.g., it counts both
commas in 'Hop,,Jump', even though), so the w it produces may be
larger than is really necessary. No real harm is done.
PROMPT ========== Q2. Possible Problems Fixed ==========
WITH cntr AS
( -- Begin sub-query cntr, to generate n (1, 2, 3, ...)
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <= 1 + (
SELECT MAX ( REGEXP_COUNT (list_txt, :sep_char) )
FROM string_test
) -- End sub-query cntr, to generate n (1, 2, 3, ...)
SELECT grp_name
, n
, REGEXP_SUBSTR ( list_txt
, '[^' || :sep_char || ']' -- Anything except sep_char ...
|| '+' -- ... one or more times
, 1
, n
) AS item_txt
FROM string_test
JOIN cntr ON n <= 1 + NVL ( REGEXP_COUNT (list_txt, :sep_char) -- Problem (1)
, 0
WHERE REGEXP_SUBSTR ( list_txt -- Problem (2)
, '[^' || :sep_char || ']' -- Anything except sep_char ...
|| '+' -- ... one or more times
, 1
, n
) IS NOT NULL
OR list_txt IS NULL -- Problems (1) and (2) together
ORDER BY grp_name
, n;
(Possible) Problems and Fixes
(1) If list_txt IS NULL, then REGEXP_COUNT (list_txt, :sep_char)
returns NULL, the join condition fails, and the output
contains nothing corresponding to the row from string_test.
If you want a NULL item to appear in the results, use
NVL to make sure the expression returns 0 instead of NULL.
(2) If list_txt contains multiple consecutive sep_chars (or if it
begins or ends with sep_char, then the original query
will return NULL items. To suppress these, add a WHERE
clause to test that the item_txt to be displayed IS NOT NULL.
PROMPT ========== Q3. Oracle 8.1 Query ===========
SELECT grp_name
, n
, SUBSTR ( list_txt
, begin_pos
, end_pos - begin_pos
) AS item_txt
FROM ( -- Begin sub-query to compute begin_pos and end_pos
SELECT grp_name
, n
, list_txt
, INSTR ( :sep_char || list_txt
, :sep_char
, 1
, n
) AS begin_pos
, INSTR ( list_txt || :sep_char
, :sep_char
, 1
, n
) AS end_pos
FROM string_test
, ( -- Begin sub-query cntr, to generate n (1, 2, 3, ...)
SELECT ROWNUM AS n
FROM all_objects
WHERE ROWNUM <= 1 + (
SELECT MAX ( LENGTH (list_txt)
- LENGTH (REPLACE (list_txt, :sep_char))
FROM string_test
) -- End sub-query cntr, to generate n (1, 2, 3, ...)
cntr
WHERE n <= 1 + ( LENGTH (list_txt)
- LENGTH (REPLACE (list_txt, :sep_char))
) -- End sub-query to compute begin_pos and end_pos
ORDER BY grp_name
, n;
/* Version-Dependent Features and Work-Arounds
The code above, Q3, runs in Oracle 8.1.
The following changes were made to Q1:
(11) REGEXP_COUNT was introduced in Oracle 11.
In earlier versions, to find the number of sep_chars in list_txt,
see how much the LENGTH changes when sep_chars are removed.
(10) REGEXP_SUBSTR was introduced in Oracle 10.
In earlier versions, use INSTR to find where the sep_chars are,
and use SUBSTR to get the sub-strings between them.
(Using this technique, 'Hop,,Jump' still contains three items,
but now item 2 IS NULL and item 3 is 'Jump'.)
(9.a) The WITH-clause was introduced in Oracle 9
In earlier versions, use in-line views.
(9.b) "CONNECT BY LEVEL < constant" doesn't work in Oracle 8.
Use ROWNUM from any sufficiently large table or view instead.
(9.c) ANSII join notation (JOIN table_name ON ...) was introduced in Oracle 9
In earlier versions, join condition go in a WHERE-clause.
*/ -
Comma separated output using report builder
Hi Experts,
I am working with EBS 11.5.10, database 9i, and report builder 6i. I have a XML Publisher report, with output type EXCEL, which is working fine. But if i get huge data like 1million, 2million, it's not able accommodate the output in EXCEL. Since it's EXCEL 2003, it can't handle data more than it's capacity(i think 60,000 rows).
So we thought, if we can generate the output in CSV file with comma separte, then we can open the file in EXCEL 2007. Could somebody help me how to generate the CSV output using report builder 6i.
or is there any work around to our problem, kindly help me, it's urgent.Hi,
Not sure if report builder can be made to generate csv output.
But you can create a PLSQL Report. Just use the query of Report Builder and write a Plsql procedure based on this query
-Idris -
Comma separated data into IN clause in oracle report query
i have a field on form as order number it takes more than one value as 1,2,3
now i want to fetch data in report query for where order no in 1,2 and 3...
but field takes value as 1,2,3...
how can i separte the comma from value and how can i pass value in IN clause...or
how can i get all records with order no 1,2,3...
please suggest how can i achieve the same....Hi Maddy....
Try this :
declare
var varchar2(10);
v1 varchar2(5);
v2 varchar2(5);
v3 varchar2(5);
vRegExp varchar2(5);
begin
var:='1,2,3';
vRegExp:='[^,]+';
FOR i IN 1..length (regexp_replace (var,vRegExp)) + 1
LOOP
v1 := REGEXP_SUBSTR (var,vRegExp);
v2 := REGEXP_INSTR(var,vRegExp,1,2);
var := substr(var,v2);
// here fetch you data from report by passing v1 as a parameter;
EXIT WHEN v2 = 0;
END LOOP;
end;
Hope this will resolve your question..
Thanks -
4.we have employee table with Empname empno and deptnum
tabel name:emp
deptno name
10 A
10 B
10 C
i need output like this
deptno name
10 A,B,CHi,
See this link
http://www.dba-oracle.com/t_converting_rows_columns.htm
There I did find query what should do what you are looking
select
deptno,
rtrim (xmlagg (xmlelement (e, ename || ',')).extract ('//text()'), ',') enames
from
emp
group by
deptno
;Regards,
Jari -
Comma separated values into MV
Hi,
I'm importing FIM data via a SQL agent and I have a column with this data:
00E704CB-40AE-0616-5B5A-6E0965BD5616,018F1801-34AE-FEE9-F98D-86E484F1812D
when the import runs, I see in the CS Object Properties that the new value is
00E704CB-40AE-0616-5B5A-6E0965BD5616\,018F1801-34AE-FEE9-F98D-86E484F1812D
Whats appenning and how can I tell FIM not to do this?
Many, many thanks,
DDIs the attribute configured as a DN or reference attribute?
What's happening is it is escaping a dn.
David Lundell, Get your copy of FIM Best Practices Volume 1 http://blog.ilmbestpractices.com/2010/08/book-is-here-fim-best-practices-volume.html -
Converting comma separated string into rows
for my procedure varchar2 is i/p paramter. i will get this i/p from java. this string value is like 'VTP,VR','VM'.
i want to split taht string into rows ie o/p will be
VTR
VR
VM.
how to do this.Hi,
As always, the solution depends on your data, your requirements, and you Oracle version.
Here's one way:
-- Simulating Java input with a bind variable:
VARIABLE str VARCHAR2 (100)
EXEC :str := 'VTP,VR,VM';
SELECT LEVEL AS n
, REGEXP_SUBSTR ( :str
, '[^,]+'
, 1
, LEVEL
) AS str_part
FROM dual
CONNECT BY LEVEL <= 1 + REGEXP_COUNT (:str, ',')
I'm just guessing that your original string doesn't include single-quotes after VR or before VM. If it does, you can use TRIM to remove them from the string passed back by REGEXP_SUBSTR. -
Hi, am new to oracle pls help me with the below query.....
i have below table
empname deptno
ssss 10
aaaa 10
www 10
qqqq 20
eeee 20
i need a output like this
deptno empname
10 ssss ,aaaa ,www
20 qqqq ,eeee
thanks in advanceIn 11gR2:
SQL> select deptno, listagg(ename, ',') within group (order by ename) enames from emp
group by deptno
DEPTNO ENAMES
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES,SCOTT,SMITH
30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
3 rows selected. -
SSRS Report : Comma Separated Hyperlinks
Hello,
I want to display Comma Separated Hyperlinks in SSRS Report. I am not sure what should I change here to get this working.
Below is the flow of data.
1. Extracting value from the SharePoint List using SSIS Package Script component and filling data in SQL Table.
I have used this Table and created below view to stuff all these three links together.
SELECT ID, STUFF
((SELECT ', ' + BCM.BCMProgramDocument
FROM BCMProgramDocumentation BCM
WHERE BCM.Risk = R.ID FOR XML PATH('')), 1, 1, '') AS BCMDoc
FROM Risk R
which gives me below output, not sure why.
"<a href='http://yahoo.com'>YAHOO</a>", "<a href='http://gmail.com'>GMAIL</a>", "<a href='http://hotmail.com'>HOTMAIL</a>"
Then in the SSRS Reporting, I have placed a PlaceHolder with HTML View selected and gave above field value in the expression.
They are not appearing as comma separated Hyperlinks.
Can anyone please help me on this ? What are the changes required in above steps ?
Thank you,
Mittal.Hi Mittal,
According to your description, you want to show three links together with comma separated from BCMProgramDocument column to a report table. After testing the issue in my environment, we can refer to the following steps to achieve your requirement:
Use the following query create a dataset:
select * from BCMProgramDocumentation
Click Fields in the left pane, add a Calculated Field as below:
Field Name: ID2 Field Source: 1
Drag a table to design surface, then insert the expression below in the detail row:
=JOIN(lookupset(Fields!ID2.Value,Fields!ID2.Value,Fields!BCMProgramDocument.Value,"DataSet1"),",")
Right-click the Placeholder to open Placeholder Properties, then select ‘HTML-Interpret HTML tags as styles’ as Markup type.
The following screenshot is for your reference:
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
I am looking for a method to translate a string with comma separated data into an array or vector.
Hello rolivawdaneel, I hope this help you, this takes the string a returns a vector.
import java.util.StringTokenizer;
import java.util.Vector;
public class stringConverter {
public static Vector toVector( String s ) {
Vector result = new Vector();
StringTokenizer st = new StringTokenizer( s, "," );
while( st.hasMoreTokens() ) {
String aTokenizedString = st.nextToken();
result.addElement( aTokenizedString );
return result;
} -
Need to Convert Comma separated data in a column into individual rows from
Hi,
I need to Convert Comma separated data in a column into individual rows from a table.
Eg: JOB1 SMITH,ALLEN,WARD,JONES
OUTPUT required ;-
JOB1 SMITH
JOB1 ALLEN
JOB1 WARD
JOB1 JONES
Got a solution using Oracle provided regexp_substr function, which comes handy for this scenario.
But I need to use a database independent solution
Thanks in advance for your valuable inputs.
GeorgeGo for ETL solution. There are couple of ways to implement.
If helps mark -
When I import a text file(comma separated) into a numbers spreadsheet all the data goes into one column instead of individual columns based on the comma separators. Excel allows you to do this during the import.. Is there a way to accomplish this in numbers without opening it in Excel and the importing into Numbers.
Your user info says iPad. This is the OS X Numbers forum. Assuming you are using OS X… Be sure the file is named with a .csv suffix.
(I don't have an iPad, so I don't know the iOS answer.) -
SQL - Multiple Fetch into Single Column with Comma Separator
Hello Experts,
Good Day to all...
I need your help on following scenarios. The below query returns set of titleID strings. Instead of printing them one below the other as query output, I want the output to be in batch of 25 values.i.e each row should have 25 values separated by comma. i.e If there are 100 titles satisfying the output, then there should be only four rows with and each row having 25 titles in comma separated manner.
SELECT DISTINCT title_id
FROM pack_relation
WHERE package_id IN ( SELECT DISTINCT fa.package_id
FROM annotation fa
GROUP BY fa.package_id
HAVING COUNT
(fa.package_id) <100);I tried with the PL/SQL block; whereas it is printing all the values continously :(
I need to stop with 25 values and display.
If its possible with SQL block alone; then it would be of great help
DECLARE
v_str VARCHAR2 (32767) := NULL;
CURSOR c1
IS
SELECT DISTINCT title_id
FROM pack_relation
WHERE package_id IN ( SELECT DISTINCT fa.package_id
FROM annotation fa
GROUP BY fa.package_id
HAVING COUNT
(fa.package_id) <100);
BEGIN
FOR i IN c1
LOOP
v_str := v_str || ',' || i.title_id;
END LOOP;
v_str := SUBSTR (v_str, 2);
DBMS_OUTPUT.put_line (v_str);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('Error-->' || SQLERRM);
END;Thanks...You can use CEIL
Sample code
SELECT
nt,
LTRIM(MAX(SYS_CONNECT_BY_PATH(val,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concat_val
FROM
SELECT
val,
nt,
ROW_NUMBER() OVER (PARTITION BY nt ORDER BY val) AS curr,
ROW_NUMBER() OVER (PARTITION BY nt ORDER BY val) -1 AS prev
FROM
SELECT
level AS val,
ceil(rownum/3) as nt /* Grouped in batches of 3 */
FROM
dual
CONNECT BY level <= 10
GROUP BY
nt
CONNECT BY prev = PRIOR curr
AND nt = PRIOR nt
START WITH curr = 1;
NT CONCAT_VAL
1 1,2,3
2 4,5,6
3 7,8,9
4 10Your code
SELECT
nt,
LTRIM(MAX(SYS_CONNECT_BY_PATH(title_id,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concat_val
FROM
SELECT
title_id,
nt,
ROW_NUMBER () OVER (PARTITion BY nt ORDER BY title_id) AS curr,
ROW_NUMBER() OVER (PARTITION BY nt ORDER BY title_id) -1 AS prev
FROM
SELECT
title_id,
ceil(rownum/25) AS nt /* Grouped in batches of 25 */
FROM
pack_relation tdpr
JOIN annotation fa
ON
tdpr.package_id = fa.package_id
GROUP BY
title_id,
fa.package_id
HAVING
COUNT (fa.package_id) < 500
GROUP BY
nt
CONNECT BY prev = PRIOR curr
AND nt = PRIOR nt
START WITH curr = 1; -
Comma separated column into rows for each value
experts,
I have a two column table. The second column has comma separated string values. How can I put the values separate for each comma separated and make one row for each value?
example,
column1 | StringColumn
s1 | test, joy, happy
s2 | USA, England, India
I want the result to be like below
column1 | StringColumn
s1 | test
s1 | joy
s1 | happy
s2 | USA
s2 | England
s2 | India
thanks in advance
ebroHello ebro,
See the following for a possible solution:
http://gallery.technet.microsoft.com/scriptcenter/Convert-Small-CSV-Value-to-ffc142ff
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Obtaining comma-separated list of text values associated with bitwise flag column
In the table msdb.dbo.sysjobsteps, there is a [flags] column, which is a bit array with the following possible values:
0: Overwrite output file
2: Append to output file
4: Write Transact-SQL job step output to step history
8: Write log to table (overwrite existing history)
16: Write log to table (append to existing history)
32: Include step output in history
64: Create a Windows event to use as a signal for the Cmd jobstep to abort
I want to display a comma-separated list of the text values for a row. For example, if [flags] = 12, I want to display 'Write Transact-SQL job step output to step history, Write log to table (overwrite existing history)'.
What is the most efficient way to accomplish this?Here is a query that gives the pattern:
DECLARE @val int = 43
;WITH numbers AS (
SELECT power(2, n) AS exp2 FROM (VALUES(0), (1), (2), (3), (4), (5), (6)) AS n(n)
), list(list) AS (
SELECT
(SELECT CASE WHEN exp2 = 1 THEN 'First flag'
WHEN exp2 = 2 THEN 'Flag 2'
WHEN exp2 = 4 THEN 'Third flag'
WHEN exp2 = 8 THEN 'IV Flag'
WHEN exp2 = 16 THEN 'Flag #5'
WHEN exp2 = 32 THEN 'Another flag'
WHEN exp2 = 64 THEN 'My lucky flag'
END + ', '
FROM numbers
WHERE exp2 & @val = exp2
ORDER BY exp2
FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)')
SELECT substring(list, 1, len(list) - 1)
FROM list
Here I'm creating the numbers on the fly, but it is better to have a table of numbers in your database. It can be used in many places, see here for a short discussion:
http://www.sommarskog.se/arrays-in-sql-2005.html#numbersasconcept
(Only read down to the next header.)
For FOR XML PATH thing is the somewhat obscure way we create concatenated lists. There is not really any using trying to explain how it works; it just works. The one thing to keep in mind is that it adds an extra comma at the end and the final query strips
it off.
This query does not handle that 0 has a special meaning - that is left as an exercise to the reader.
Erland Sommarskog, SQL Server MVP, [email protected]
Maybe you are looking for
-
Help on creating a ServerSession in Eclipse with XML file
Hi, I am using Toplink in Eclipse with Tomcat/Apache (or at least trying to :) I am trying to make the following code work: Project myProject = XMLProjectReader.read("myproject.xml"); Server serverSession = myProject.createServerSession(); but I get
-
I have just went to use my airplay and my airplay is asking for an apple passcode which I didn't set any suggestions
-
HELP!!!! problem with motherboard HP Probook 4520s , need replacement, where can i buy it??
-
Unable to print AP Check with MICR on AIX. The PDF output displays the MICR
I have peculiar situation here and I would really appreciate any help I can get. The issue: The requirement here is to print an AP Check with the MICR. Using XML I have defined a template and when I preview the output in PDF, the MICR string displays
-
Data Source CE in Visual Composer
Hello Experts, we are running on CE 7.2. I wanted to read BPM task details into a custom application or generate a report of who has claimed the task,currently being processed by whom and the history of this information relating to every task in uw