Comma separated data to array
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;
}
Similar Messages
-
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 -
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 -
Sqlloader:only 1st when clause works for comma separated data file
LOAD DATA
INFILE 'XXMI_SUPPLIER_DATA.dat'
REPLACE
INTO TABLE APPS.XXMI_AP_SUPPLIERS_STG
when interface_record_type = '01'
Fields terminated by "," Optionally enclosed by '"'
TRAILING NULLCOLS
and
INTO TABLE APPS.XXMI_AP_SUPPLIER_SITES_STG
when interface_record_type = '02'
Fields terminated by "," Optionally enclosed by '"'
TRAILING NULLCOLS
always getting the error for second when clause:
4 Rows not loaded because all WHEN clauses were failed.
pls any one can throw some light on this?What's Oracle version.
What's your datafile looks like. Post a few sample line here.
when interface_record_type = '01'You didn't define interface_record_type in your when clause.
Sample,
INTO TABLE dept
WHEN recid = 1
(recid FILLER INTEGER EXTERNAL TERMINATED BY WHITESPACE,
deptno INTEGER EXTERNAL TERMINATED BY WHITESPACE,
dname CHAR TERMINATED BY WHITESPACE) check Oracle doc,
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_control_file.htm#i1004788 -
Comma separated format is required
Hi all
this is the code which i have written:
OPEN DATASET g_ufile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT t_file WHERE werks = t_file1-werks.
MOVE : gc_kaganplntcode TO t_file-fieldname1,
gc_productcode TO t_file-fieldname2,
gc_qtyavailable TO t_file-fieldname3.
CONCATENATE t_file-fieldname1
t_file-fieldname2
t_file-fieldname3
INTO gv_itemdet1 separated by ','.
ENDLOOP.
transfer gv_itemdet1 to g_ufile.
loop at t_file into t_file1.
condense t_file1 no-gaps.
transfer t_file1 to g_ufile.
append t_file1.
clear t_file1.
clear gv_itemdet.
endloop.
in t_file1 data is coming in continous manner. i need to have comma separated data. ie each field shud be separated by ','.
can anybody tell me logic for it.
very urgent.
regrd
Mona
Edited by: Alvaro Tejada Galindo on Apr 14, 2008 1:03 PMTry it this way mona
Declare a fiel-symbol type any and an string to tranfer the contents.
loop at t_file into t_file1.
clear string.
condense t_file1 no-gaps.
do.
assign component sy-index of structure t_file1 to <fs>.
if sy-subrc ne 0.
exit.
endif.
concatenate string <fs> ',' into string.
enddo.
transfer string to g_ufile.
append t_file1.
clear t_file1.
clear gv_itemdet.
endloop. -
Combine data from a table and insert to another in comma separated format
In my SQL database table i have some data as shown below.
KNO Course Grade Institution
124 BTECH First IIT Calicut
128 BE First KKS Institute
124 CCNA Q NIIT Delhi
124 DDCN Q Appl Calicut
128 DIT A NIIT Delhi
128 VB Q IICM Delhi
i want this courses to be arranged as sample given under to a table named mainpers
KNO Course
124 BTECH[First], CCNA[Q],DDCN[Q]
128 BE[First], DIT[A], VB[Q]
I am a System Administrator at VadodaraYou can do this in SQL.
with cte as (
select distinct KNO
from Table1
select KNO
, Stuff(
(select ',' + Course + '[' + Grade + ']'
from Table1
where Table1.KNO = cte.KNO
for xml path ('')
), 1, 1, '') as Course
from cte
http://davidduffett.net/post/5334646215/get-a-comma-separated-list-of-values-in-sql-with-for
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com -
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.) -
Flat files data comma separated using SSIS.
Hi,
I have multiple flat files which come in comma separated columns. See example below :
Customer Data
CustID,FName,LName,Disease,Email,Phone
12345,Xyz,Smit,Bronchitis, Asthma and fever,[email protected],80000000
12346,Abc,Doe,fever Headache,[email protected],90000000
12347,Klu,joe,Sugar, cough and fever,[email protected],12345678
Please look at the ID's 12345 and 12347. The disease column has a internal comma space between. How do i remove the comma spaces in the disease column, so that it can be loaded from flat file to sql table using SSIS. ?
Please help !
ThanksHere is a full solution base on my post above (first option)
1. create temp table (Give it a unique name):
create table #T (Txt NVARCHAR(MAX))
GO
2. Insert all the data into temporary table. Each line in the text file, is a value for one column in a row in the table.
-- I will jump to the table and use simple insert.
-- If you have problem with step 1 then please inform us (this is simple bulk insert basically)
insert #T (Txt) values
('1234435,Xyz,Stemit,Brfsdonchitis, Asthma and fever,[email protected],80000000'),
('12346,Agjdfjbc,Doge,fevhhhher Headsxdshhache,[email protected],90000000'),
('123447,Klu,joe,Sugar, cough and fever,[email protected],12345678')
GO
the result should be like this:
Txt
1234435,Xyz,Stemit,Brfsdonchitis, Asthma and fever,[email protected],80000000
12346,Agjdfjbc,Doge,fevhhhher Headsxdshhache,[email protected],90000000
123447,Klu,joe,Sugar, cough and fever,[email protected],12345678
I use a SPLIT Function named Split_CLR_Fn. This is a CLR Split function that get input <string to split> and <string as delimiter,> and it return table with 2 columns ID, SplitData
For example if you use: SELECT * from Split_CLR_Fn('text1,text2,text3,',') then you get result:
ID SplitData
1 Text1
2 Text2
3 Text3
** You can find in the internet several good functions, I HIGHLY RECOMMENDED NOT TO USE T-SQL FUNCTIONS but CLR FUNCTION. Check thi link to understand why:
http://sqlperformance.com/2012/07/t-sql-queries/split-strings
** This is the best function that I know about and I use it, but I change the code a bit to return 2 columns and not just the SplitData as in this blog: http://sqlblog.com/blogs/adam_machanic/archive/2009/04/28/sqlclr-string-splitting-part-2-even-faster-even-more-scalable.aspx
That's it :-) we are ready for the solution which is very simple
Solution 1 (BAD solution but easy to write):
select
(select SplitData from Split_CLR_Fn(Txt,',') where ID = 1) CustID,
(select SplitData from Split_CLR_Fn(Txt,',') where ID = 2) FName,
(select SplitData from Split_CLR_Fn(Txt,',') where ID = 3) LName,
STUFF((select ',' + SplitData from Split_CLR_Fn(Txt,',') where ID > 3 and ID < (select MAX(ID) from Split_CLR_Fn(Txt,',')) - 1 for XML path('')), 1 , 1,'') Disease,
(select SplitData from Split_CLR_Fn(Txt,',') where ID = (select MAX(ID) from Split_CLR_Fn(Txt,',')) - 1) Email,
(select SplitData from Split_CLR_Fn(Txt,',') where ID = (select MAX(ID) from Split_CLR_Fn(Txt,','))) Phone
from #T
GO
Solution 2: better in this case since the format is constant (this is the solution I wrote about above)
;With MyCTE as (
select
Txt,
SUBSTRING(Txt, 1, CHARINDEX(',', Txt, 1) - 1) as CustID
, SUBSTRING(
Txt
,CHARINDEX(',', Txt, 1) + 1 -- I start from the end of preview len
, CHARINDEX(',', Txt, CHARINDEX(',', Txt, 1)+1)- CHARINDEX(',', Txt, 1) - 1
) as FName
, SUBSTRING(
Txt
,CHARINDEX(',', Txt, CHARINDEX(',', Txt, 1)+1)+1 -- I start from the end of preview len
, CHARINDEX(',', Txt, CHARINDEX(',', Txt, CHARINDEX(',', Txt, 1)+1)+1) - CHARINDEX(',', Txt, CHARINDEX(',', Txt, 1)+1) - 1
) as LName
, RIGHT(Txt, CHARINDEX(',', REVERSE(Txt), 1) - 1) as Phone
, RIGHT(LEFT(Txt, Len(Txt) - Len(RIGHT(Txt, CHARINDEX(',', REVERSE(Txt), 1) - 1)) - 1), CHARINDEX(',', REVERSE(LEFT(Txt, Len(Txt) - Len(RIGHT(Txt, CHARINDEX(',', REVERSE(Txt), 1) - 1)) - 1)), 1) - 1) as Email
from #T
select CustID,FName,LName, Phone, Email, SUBSTRING(Txt, Len(CustID) + Len(FName) + Len(LName) + 4, Len(Txt) - Len(Email) - LEN(Phone) - Len(CustID) - Len(FName) - Len(LName) - 5) as Disease
from MyCTE
I hope that this is useful :-)
Ronen Ariely
[Personal Site] [Blog] [Facebook] -
Convert work area data into comma separator format ( CSV format )
the function moudule sap_convert_to_csv_format is not available in my system . it is a not released fm as of now. so i cant use it.
My requirement is to send the details to app server in a comma separated format.
For each work area , which i transfer to application server, i hv to separte each field by a comma separtaor.
TRANSFER wa to VA_FILENAME LENGTH 256 ENF OF LINE.
Suppose my work area has fields wa-f1 wa-f2 wa-f3, it should write in app server as value1, value2, value3 like wise....
Suggest me if there is any alternative function module to acheiver this like when we pass wa to fm, the fields should be comma separator,
Any other useful suggestions are welcome.
ThanksHi,
here is the piece of code to transfer data from internal table to applivcation server as a comma seperated file..
FORM comma_sep_file .
DATA: l_cost_center_str TYPE type_cost_center.
IF it_cost_center[] IS NOT INITIAL.
**Concatenate file path and file name
CONCATENATE p_cpath p_cfile INTO v_cost_cen_output.
OPEN DATASET v_cost_cen_output FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
If Network file could not be opened, give a message.
IF sy-subrc <> 0.
WRITE : / text-030 , v_cost_cen_output .
MESSAGE s000(zp) WITH text-015 .
CLEAR : v_cost_cen_output,
p_cpath .
ELSE.
LOOP AT it_cost_center INTO l_cost_center_str.
CONCATENATE l_cost_center_str-co_cen_code
l_cost_center_str-co_cen_name
l_cost_center_str-fld3
l_cost_center_str-fld4
l_cost_center_str-set_true INTO wa_csvdata
SEPARATED BY c_const_sep.
TRANSFER wa_csvdata TO v_cost_cen_output.
CLEAR wa_csvdata.
ENDLOOP.
ENDIF."IF sy-subrc <> 0.
CLOSE DATASET v_cost_cen_output.
ENDIF.
ENDFORM. "
i hope this will help you...
Thanks & Regards
Ashu Singh -
Converting xml data in to comma separated values in bpel
Is there a way to covert generic xml data to comma separated value in BPEL? i have tried using createDelimitedString but no luck.
Please guide me on this issue.
Thanks!
Shan
Edited by: 876372 on Aug 3, 2011 6:58 AMHi,
Have a luk at the below link it has many examples:
http://download.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/nfb.htm -
Result may contain single string or comma separated need to split into rows
Hi, All... I've searched through the forums and found plenty on splitting comma separated into rows; though I'm struggling applying it to my situation. I have data that looks like the below where I need to split a value into multiple rows if it should be but the same field in the table may also contain a string that should not be separated (indicated by the "Array" field being 0 or 1)...
WITH t AS
(SELECT 1 as array, '"Banana", "Apple", "Pear"' as str FROM dual union all
SELECT 0, 'Fruit is delicious' FROM dual union all
SELECT 0, 'So are vegetables' FROM dual union all
SELECT 1, '"Bean", "Carrot", "Broccoli"' FROM dual union all
SELECT 1, '"Apple", "Banana"' FROM dual)I've looked through many of the connect_by posts on the forum and I haven't come across one that splits a field if it should be but doesn't if it should not be... may have missed it because there are plenty of these requests on the forum!
If you're feeling even more ambitious - the ultimate goal is to count the number of times a particular answer appears in an array - so notice the last portion of the data contains "Apple", "Banana"... the result would show:
RESULT
Banana 2
Apple 2
Pear 1
Bean 1
Carrot 1
Broccoli 1
Fruit is delicious
So are vegetablesI can always sort them later based on other fields in the table - but the result above would be my ultimate goal!
Any help is always appreciated. Thanks! 11gHi,
The examples you found should work for you. Just use a CASE expression to determine if str needs to be split or not, by looking at array.
Here's one way:
WITH got_part_cnt AS
SELECT array, str
, CASE
WHEN array = 0
THEN 1
-- ELSE 1 + REGEXP_COUNT (str, '", "') -- See note below
ELSE 1 + ( ( LENGTH (str)
- LENGTH (REPLACE (str, '", "'))
/ 4
END AS part_cnt
FROM t
, cntr AS
SELECT LEVEL AS n
FROM (
SELECT MAX (part_cnt) AS max_part_cnt
FROM got_part_cnt
CONNECT BY LEVEL <= max_part_cnt
, got_sub_str AS
SELECT CASE
WHEN p.array = 0
THEN p.str
ELSE REGEXP_SUBSTR ( p.str
, '[^"]+'
, 1
, (2 * c.n) - 1
END AS sub_str
FROM got_part_cnt p
JOIN cntr c ON c.n <= p.part_cnt
SELECT sub_str
, COUNT (*) AS cnt
FROM got_sub_str
GROUP BY sub_str
ORDER BY cnt DESC
, sub_str
{code}
The only database at hand right now is Oracle 10.2, which doesn't have REGEXP_COUNT. I had to use a complicated way of counting how many times '", "' occurs in str in order to test this in Oracle 10. Since you have Oracle 11, you can un-comment the line that uses REGEXP_COUNT in the first CASE expression, and remove the alternate ELSE clause (that is, the next 5 lines, up to END).
To make sure that this query is really paying attention to array, I added this row to the sample data:
{code}
SELECT 0, '"Bean", "Carrot", "Broccoli"' FROM dual union all
{code}
Even though str looks just like a delimited list, array=0 tells the query not to split it, so it produces these results:
{code}
SUB_STR CNT
Apple 2
Banana 2
"Bean", "Carrot", "Broccoli" 1
Bean 1
Broccoli 1
Carrot 1
Fruit is delicious 1
Pear 1
So are vegetables 1
{code} -
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] -
Comma Separated Value Taking too Much Time to Execute
Hi,
select ES_DIAGNOSIS_CODE DC from ecg_study WHERE PS_PROTOCOL_ID LIKE 'H6L-MC-LFAN'
The above query returns comma separated value from the above query.
I am using the query below to split the comma separated value but the below query is taking lot of time to return the data.
SELECT
select DC from (
with t as ( select ES_DIAGNOSIS_CODE DC from ecg_study WHERE PS_PROTOCOL_ID LIKE 'H6L-MC-LFAN' )
select REGEXP_SUBSTR (DC, '[^,]+', 1, level) DC from t
connect by level <= length(regexp_replace(DC,'[^,]*'))+1 )
Please suggest me is there any alternative way to do this comma separated value.
Thanks
SudhirNikolay Savvinov wrote:
Hi BluShadow,
I know that this function is fast with varchar2 strings from several years of using it. With CLOBs one may need something faster, but the OP didn't menion CLOBs.
Best regards,
NikolayJust because you perceive it to be fast doesn't mean it's faster than doing it in SQL alone.
For starters you are context switching from the SQL engine to PL/SQL to call it.
Then in your code you are doing this...
select substr(v_str,v_last_break+1, decode(v_nxt_break,0,v_length, v_nxt_break-v_last_break-1)) into v_result from dual;which is context switching back from the PL/SQL engine to the SQL engine for each entry in the string.
Why people do that I don't know... when PL/SQL alone could do it without a context switch e.g.
v_result := substr(v_str,v_last_break+1, case when v_nxt_break = 0 then v_length else v_nxt_break-v_last_break-1 end);So, if you still think it's faster than pure SQL (which is what the OP is using), please go ahead and prove it to us. -
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 -
TAB SEPARATED instead of COMMA SEPARATED
Hi everybody,
I need to generate a Comma Separated File with reports 9i. As I read here on OTN I defined Destination Format as DELIMITEDDATA and I tried DELIMITED. In the first try, report builder crashed instantly and in the latter try, report builder creates a TAB SEPARATED file.
When I open (import) this file to Excell, the data are put in one cell in a rather unreadable form.
Does anyone have an idea how to get the result in a REAL COMMA SEPARATED FILE???
Thanx
HansUse the parameter DELIMITER=',' .
I think it works
Ashok
Maybe you are looking for
-
Immediately after installation of PS CS6 the application correctly detected my grafics adapter AMD HD7750 and in the PS GPU settings the grafic processing unit support was activated. Now this option is deactivated and cannot be activated any more. PS
-
BPM Error: Timeout condition of pipeline reached- After transporting to Prd
Hi, I am doing Sync/Async BPM scenario. -> Receive message and process it and send to BI and response has to send back to the sender. start ->Receive(Request)> Transformation(Responsemap)>Send(SendtoR/3)->Send(Send Response) ---> stop. It is working
-
Urxvt patch: VTE like clear screen behavior
I've switched to urxvt last week. I come from the VTE world (gnome-terminal, xfce-terminal and such, the latter in my case). VTE has a nice feature to which I've accustomed myself. This is the way how it handles the clear screen function (ctrl-L). In
-
Which profile is used for PRODUCTION SERVER
Dear friends, in Production client... which profile is selected for client copy LEE
-
PLEASE Help!!! - G4 keeps crashing on me!
this has never happened to me with my mac before so i really dont know what to do! i boot up and sometimes it runs fine for about 20 minutes before it freezes up and crashes! then i re-boot and sometimes it runs fine but most of the time it doesnt re