comma separator
Hello
In Oracle 10 g, I need to split comma separation like that.
data:
'1,3,2,3,4,6'
to divide like this
Col1 col2
1 3
2 3
4 6
Thanks in advance
Hello 00125
This might be a solution:
WITH TMP_TAB
AS (SELECT '1,3,2,3,4,6' AS DOUBLE TXT)
SELECT REGEXP_SUBSTR (txt, ' [^,] +', 1, 2 + 1 *(level-1)) AS Col1
REGEXP_SUBSTR(txt, '[^,]+', 1, 2*level) AS Col2
OF TMP_TAB
CONNECTION OF level <= round((length(txt)="" -="" length(replace(txt,="" ',')))="" 2) ="" --="">10g characteristic
;
Less than 11g, you can write it's simpler:
CONNECTION OF <= regexp_count(txt="" ||="" ',',="" ',')="" 2 ="" --="">11g characteristic level
=>=>
I hope it helps.
Best regards, David
Tags: Database
Similar Questions
-
I have a string that comes an external instrument. When it is read, he appears in a format like this:
"10,55.
11.25
13.43
15.68 "
The number of entries varies. I need to get this string in a comma-separated string that is later concatenated with another string and written to a csv file.
So how do the entry above into this: ' 10,55, 11.25, 13.43 15.68?
Thank you
There are a lot of ways. I use find and replace. See attachemt for an example.
-
Adding zero in comma separated string
Hi all
Currently I am working on Oracle 11 g
I have the string as 1,12,123,1234 and my requirement is to fill the zero on every comma separated string
My output result should be like this 0001,0012,0123,1234, what exactly does lpad('12',4,'0').
Kindly help a query above.
A simple trick I learned for a long time back here
SQL> with t 2 as 3 ( 4 select '1,12,123,1234' str from dual 5 ) 6 select regexp_replace(regexp_replace(str, '([[:digit:]]+)', '0000\1'), '0+([[:digit:]]{4})', '\1') str 7 from t; STR ------------------- 0001,0012,0123,1234 SQL>
-
The research of a column with comma separated values with ora-text
I use the Oracle 11 g 2 XE and Oracle Text to a web search engine.
I've now created and text indexed a CLOB keywords column that contains words separated by spaces. This allowed me to expand the search, as Oracle Text returns the rows that have one or more keywords that are stored in this column. The contents of the column are visible to the user and serves to 'expand' the search. This does not work as expected.
But now I need support several words or even sentences. With the current configuration, Oracle Text will only search for each keyword. How should I store the phrases and configure Oracle text so that it will search entire sentences (exact match is better, but the partial match is fine too)?
Example of content column of two lines (values separated semicolon):
"Hello, Hello; y at - it anyone out there? Nope; »
"the just; basic facts; »
I found a similar question: looking for a column with values separated by commas, except that I need a solution for Oracle 11 g with it's freetext search.
Possible solutions:
1st solution: I thought to redraw the DB as follows. I would like to make a new array of keywords (pkID NUMBER, nonUniqueID NUMBER, singlePhrase VARCHAR2 (100 BYTE)). And I want to change the column previous keyword to KeywordNonUniqueID, holding the ID (instead of a list of values). At the time of the research I had INNER JOIN with the new keyword table. The problem with this solution is that I will get several lines containing the same data except for the sentence. I guess this will destroy the ranking?
2nd solution: is it possible to store sentences as an XML in the column key of origin and somehow say Oracle text to search for in the XML?
3rd solution: separate individual phrases with spaces, but replace the spaces in sentences with the underscore or something (making a single word). If a phrase "why Hello there, Johnny!" is saved as "Why_hello_there, _Johnny!
4th solution?:
Note that, generally, there is a lot of sentences (less than 100), nor that they will be long (one sentence will be up to 5 words).
Also note that I am currently using CONTAINS, and needs some of its operators, to my full-text searches.When you talk about "phrase", do you mean "a list of words separated by a comma other sentences?
Isn't that the definition of "sentence" used by Oracle Text, where it simply means "a list of words in the order defined."
If I understand your requirement, you want to have data such as:
"aa bb cc dd".
"aa ee dd ff.and give priority to the first on the second if someone looking for "dd".
First, to conduct research in the comma separated list, you should look for in a section. You can either explicitly define sections of field such as
AA bb cc dd
Or you can use the PHRASE special section and set the sentence delimiters correctly. This is done with the attribute BASIC_LEXER punctuationThen you have the number you want to find only words where they are the only words in the section. That's the same problem, I address in the last post of this forum entry:
Contains: match exactlyOur solution will be substantially the same, some surrounding text with special markers, and then prioritize a phrase search with these special markers each side of the word.
We need to do a treatment some additional, although, as we need to surround each "sentence" (in your terminology) with special markers. I did it by surrounding the text with "XX1"... Condition2"then by replacing every comma with"Condition2, XX1"as part of a MULTI_COLUMN_DATASTORE:drop table names; create table names (id number primary key, text varchar2(50)); insert into names values( 1, 'just and kind, kind and loving' ); insert into names values( 2, 'just, kind' ); exec ctx_ddl.drop_preference ( 'mylex' ) exec ctx_ddl.create_preference( 'mylex', 'BASIC_LEXER' ) exec ctx_ddl.set_attribute ( 'mylex', 'PUNCTUATIONS', ',' ) exec ctx_ddl.drop_preference ( 'mcds' ) exec ctx_ddl.create_preference( 'mcds', 'MULTI_COLUMN_DATASTORE' ) exec ctx_ddl.set_attribute ( 'mcds', 'COLUMNS', '''XX1 ''||replace(text, '','',''XX2, XX1'')||'' XX2''' ) exec ctx_ddl.drop_preference ( 'mywl' ) exec ctx_ddl.create_preference( 'mywl', 'BASIC_WORDLIST' ) exec ctx_ddl.set_attribute ( 'mywl', 'SUBSTRING_INDEX', 'YES' ) create index namesindex on names(text) indextype is ctxsys.context parameters( 'datastore mcds wordlist mywl' ) / select score(1),id,text from names where contains( text, '
XX1 kind XX2 kind Output of this is:
SCORE(1) ID TEXT ---------- ---------- -------------------------------------------------- 52 2 just, kind 2 1 just and kind, kind and loving
-
SQL - Multiple Fetch in a single column with a comma separator
Hello Experts,
Good day to all...
I need your help on the following scenarios. The following query returns all channels titleID. Rather than print them one under the other as a result of the query, I want the output to be in the batch of 25 values.i.e than each line must have 25 values separated by commas. IE if there are 100 titles satisfying the output, then there should be only four lines with and each line with 25 titles in comma separated way.
I tried with the PL/SQL block; Whereas it is printing all the values permanently :(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 have to stop with 25 values and display.
If its possible with SQL block alone. then it would be a great help
Thank you...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;
You can use CEIL
Code example
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 10
Your 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;
-
How to remove duplicates from comma separated string
Hi allI have an obligation to remove duplicates of string separated by commas:
Some examples of code (real data can be in millions)
{code}
create table test_dup_del (num number (10), dup_val varchar2 (100));
insert into test_dup_del values (1234, '1, 2, 3, 4, 3, 1');
insert into test_dup_del values (4567,'1, 2, 2, 4, 4, 1');
insert into test_dup_del values (7894,'1, 2, 1, 3, 3, 1');
insert into test_dup_del values (1478, '1, 2, 4, 4, 3, 2');
insert into test_dup_del values (2589, '1, 2, 1, 2, 1, 2');
commit;(code}
my output would be:
1234, 1, 2, 3, 4'
4567, '1, 2, 4'
7894, '1, 2, 3'
1478, 1, 2, 3, 4'
2589, 1, 2'
Thank you
Rachid
If there is a real need to split the data so that it could be corrected (before split to store correctly... Tip tip!) ...
SQL > ed
A written file afiedt.buf1 with test_dup_del (num, dup_val) as)
2 Select 1234, 1, 2, 3, 4, 3, 1' Union double all the
3 select 4567, 1, 2, 2, 4, 4, 1' Union double all the
4 Select 7894, 1, 2, 1, 3, 3, 1' Union double all the
5 Select 1478, 1, 2, 4, 4, 3, 2' of all the double union
6 select 2589, 1, 2, 1, 2, 1, 2' of the double
7 )
8 --
9. end of test data
10-
11, split as)
12. Select num
13, trim (regexp_substr(dup_val,'[^,]+',1,level)) as val
14 from test_dup_del
15 connect by num = num prior
16 and level<=>=>
17 and prior sys_guid() is not null
18 )
19, dist in (select distinct)
20 num
21 ,val
22 split
23 )
24 select num
25, listagg (val, ',') within the Group (order by val) as vals
dist 26
27 * group by num
SQL > /.
NUM OF VALS
---------- ------------------------------
1234 1,2,3,4
1478 1,2,3,4
2589 1.2
4567 1,2,4
7894 1,2,35 selected lines.
-
Remove duplicates of comma separated String
Hello
I have a column that contains the values of duplicates with separated by commas.
Customer ID
-----------------------------
5,5,5,5,6,6,5,5,5,6,7,4,1,2,1,4,7,2
I wrote this:
Select REGEXP_REPLACE ('5, 5, 5, 5, 6, 6, 5, 5, 5, 6, 7, 4, 1, 2, 1, 4, 7, 2', ' (^ |,)([^,]*) (, \2)+','\1\2') of double;)
---------------------------------
5,6,5,6,7,4,1,2,1,4,7,2
But it eliminates only the continuous elements.
I want to put it as:
---------------------
5,6,7,4,1,2
Help, please.
Thank you.
Amit
Published by: 987565 on February 12, 2013 04:02Since you don't have 11 GR 2, making it a lot easier, I would use INSTR/SUBSTR to break the values, and then use START WITH / CONNECT BY to group the separate values of back together. I avoid the REGEXP stuff when I can because he uses a lot of CPU.
WITH INDATA AS ( select '9,9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1' x from dual union all select '9,9,8,8,7,7,4,4,3,3,2,2,1,1' x from dual ), TOKENIZED AS ( SELECT DISTINCT A.INNUM, dense_rank() over(partition by innum order by b.column_value) x_rank, B.COLUMN_VALUE x FROM (select rownum innum, x from indata) a, table(cast(multiset( SELECT trim(SUBSTR( x, (case level when 1 then 1 else instr(x, ',', 1, level-1) + 1 end), (case instr(x, ',', 1, level) when 0 then 4000 else instr(x, ',', 1, level) - 1 - (case level when 1 then 0 else instr(x, ',', 1, level-1) end) end) )) FROM dual CONNECT BY level <= LENGTH(x) - LENGTH(REPLACE(x, ',', '')) + 1 ) AS SYS.ODCIVARCHAR2LIST)) B ) SELECT ltrim(sys_connect_by_path(x, ','),',') x FROM TOKENIZED A where connect_by_isleaf = 1 START WITH X_RANK = 1 connect by (innum, x_rank) = ((prior innum, prior x_rank + 1)); X -------------------- 1,2,3,4,5,6,7,8,9 1,2,3,4,7,8,9
Published by: stew Ashton on February 13, 2013 15:47
-
How to list comma separated data field...?
I need to separate the list data in a column for the rendering of the data more readable.
For example:
Select * from myTable;
What I'd like to see instead:ID TEXT -- ----------- 1 RED,GREEN,BLUE,YELLOW,ORANGE,VIOLET 2 GREEN,ORCHID,SLATEBLUE,RED,YELLOW
The number if items in the TEXT column varies from a minimum of four points... She also could have more than 20!ID TEXT -- ----------- 1 RED GREEN BLUE YELLOW ORANGE VIOLET 2 GREEN ORCHID SLATE RED YELLOW
The items are all separated by a comma (no spaces).
Finally, the for now, the data doesn't have to be sorted, but would be nice in the future!
Thanks, I really appreciate any idea that you all might be able to provide!
KSL.Tom Kyte has been answering this question for years, and there's a FAQ about this somewhere here. In any case, here's my variant which manages the entrances to the channels up to 4000 bytes, because stops Tom 3998. Furthermore, some may suggest REGEXP functions which avoid because they are nice time CPU.
with indata as ( select id rowlabel, text x from mytable ) select a.rowlabel, b.column_value from indata a, table(cast(multiset( SELECT trim(SUBSTR( x, (case level when 1 then 1 else instr(x, ',', 1, level-1) + 1 end), (case instr(x, ',', 1, level) when 0 then 4000 else instr(x, ',', 1, level) - 1 - (case level when 1 then 0 else instr(x, ',', 1, level-1) end) end) )) FROM dual CONNECT BY level <= LENGTH(x) - LENGTH(REPLACE(x, ',', '')) + 1 ) as sys.odcivarchar2list)) b order by 1, 2;
Published by: stew Ashton on October 29, 2012 18:30 - example modified to use mytable OP.
-
Problem with display Inlines for comma separated output (horizontally)
Hi all
It's my XML data,
-< EMP_IDS >
-< > 10001 EMP_ID < / EMP_ID >
-< > 10002 EMP_ID < / EMP_ID >
-< > 10003 EMP_ID < / EMP_ID >
-< > 10004 EMP_ID < / EMP_ID >
-< > 10005 EMP_ID < / EMP_ID >
-< / EMP_IDS >
I show all emp_ids in a single horizontal line, separated by commas, using this code
10001,10002,10003,10004,10005.
<? xdoxslt:set_variable($_XDOCTX,'C',count(.//EMP_ID))? > <? for-each@inlines:EMP_ID? > <? ? >
<? If@inlines:position ()! = xdoxslt:get_variable($_XDOCTX,'C')? >, <? end if? >
<? If@inlines:position () = xdoxslt:get_variable($_XDOCTX,'C')? >. <? end if? >
<? end foreach? >
Question: What I want is that when my EMP_ID = ' 10002 "should NOT be displayed, so I want the output to be
10001,10003,10004,10005.
I am unable to code this, is there any way by which I can take the value 10002 in a variable and use an if statement to not show this value?
Help, please.
Thank you
Ronnycan u try this
-
How to train a xml using a comma separated string in Xquery
Hi all
In my application, I need to write an Xquery query that should be an xml document. Admission to the XQuery function is an xml with an element that has the strings separated by commas. For
example of
< root >
< StringComma > Hi, Hello, welcome < / StringComma >
< / root >
I need form an xml in such a way that it should have as many tags as the strings in < StringComma > element of the foregoing. For example, is what I want
< Root1 >
< String1 > Hello < / String1 >
< String2 > Hello < / String2 >
Welcome < String3 > < / String3 >
< / Root1 >
something like that. How could we do it using XQuery. Kindly help me in this.
Thank you.Hello
You can do it like this:
declare variable $input := document{
};Hi,Hello,Welcome { for $i at $pos in fn:tokenize($input/Root/StringComma, ",") return element {fn:concat("String", $pos)} {$i} } -
creation of selection using comma-separated values list
Hi all
I have the column in the database containing values separated by commas
for ex: Pune, Mumbai, Bangalore...
I want to create the selection list using higher values.
for ex: Pune
Mumbai
Bangalore
Please help me on this issue.
Thanks in advance,
JitendraHello
Try the following
select regexp_substr(YOUR_FIELD_NAME,'[^,]+', 1, level) display_value, regexp_substr(YOUR_FIELD_NAME,'[^,]+', 1, level) return_value from YOUR_TABLE connect by regexp_substr(YOUR_FIELD_NAME, '[^,]+', 1, level) is not null
Concerning
Graham
Published by: gpc on February 1, 2012 11:27
-
Hello
We stock values separated by commas into a table.
IIL_CUSTOMER_TICKETS_TYPE_IDS
-------------------------------------------------------
1,2,3,4,5,6
5,7,10,56,48
12,45,56,
I want to query this table through values separated by commas...
Query as this select * from t1 where IIL_CUSTOMER_TICKETS_TYPE_IDS in (1,2,3)
Help, please...Try this
with mytable as
(
Select 'a' pass, ' 1,2,3,4,5,6"txt of all double union
Select 'b', '5,7,10,56,48' of any double union
Select 'c', "12,45,56" of the double
)
Select
MyTable.col,
txt
Of
MyTable,
(
Select
level n
Of
(
Select
Max (length (txt) - length (replace (txt, ','))) as max_commas
Of
MyTable
)
connect by level<= 1="" +="">=>
) ctr
where
CTR.n<= 1="" +="" length="" (txt)="" -="" length="" (replace="" (txt,="">=>
and regexp_substr (mytable.txt, "[^,] +', 1, n") in (1,5,7)
order by
MyTable.col,
CTR.nhttp://nimishgarg.blogspot.com/2010/06/Oracle-comma-seprated-string-to-rows_16.html
Alexander gelin
http://nimishgarg.blogspot.com -
Using 'text field contains comma-separated values' on a parameter of %
Hello
I use a parameter that has more than one value to be entered, separated by commas. I checked the box 'text field contains values separated by commas' for the parameter and set the sql code by using the operator 'in' so that the column will look in the multiple input values (e.g. family name in (: surname_par)). However, as passing multiple values parameter must also be able to manage %'s. As the sql uses the 'in' operator, BI Publisher brings back an error because % is supposed to bring all family names and not people with a last name of %. Is there a way to get around this?
Thank youIf you try to pass multiple values separated by commas and in addition also takes the query to return the data when the user types just in '%', then you could write something like this in your query:
Select * from table_name
where ((1 = DECODE (: surname_par, '%', 1, 0)) OR family name in (: surname_par))I hope this helps. Please award points if helpful/correct.
-
Chr (44) to replace the commas separating the arguments of a function?
In Oracle SQL, it is possible to replace the commas between the arguments of the function with chr (44)? A simple example with substr():
substr ("yyyy", 1, 1) - the result is 'a '.
vs
substr ("aaaa" chr (44) 1 chr (44) 1)-this should also return 'a '.
Is there a way to make the second example works the same way as the first? I tried different techniques escaping, string concat, etc., and I failed. Is there a method to replace the comma (",") the character of the way I'm looking for or is this impossible?
Thank you
N °
The Analyzer seeks commas, not for other things you as a human being assimilated by a comma.
-
Function DVM on comma separated entries - SOA 11 g
Hello
We are trying to cope with a strange requirement where, as an input, we receive multiple values such as
A, B, C < input > < / input >
Now we need to apply a transform DVM on individual as values < output > X, Y, Z < / output >
I see that we can have DVM transformation on a single entry, but seen on many, I don't know if this is even possible here.
Pls suggest that if someone has never made a similar transformation.
There is no function DVM out-of-box for your condition. You can try the following
- ' create-nodeset-to-delimited string by-"allows you to create xml.
- In the XSLT file, loop through each value to call function DVM
- Convert the xml to a string result
Maybe you are looking for
-
How to uninstall Norton AntiVirus of my EL Capitan iMac running?
The version of Norton Antivirus, I had before the update to EL Captian does not work with El Capitan, apparently. I want to uninstalled and you are using Symantec Endpoint Protection (which, by the way told me, works better than Norton). When I tried
-
Qosmio F10: vertical lines on the screen
I use a Qosmio F10 with a nVIDIA 128 MB graphics card. Recently while I was running a graphics-based application on, my screen started showing me wire colors on the screen. I was able to start the game once more, but found the same problem exist. On
-
We used the kind of software that uses a key lock (which is connected to the parallel port), we have added new machines in our Mt. HP3330 company, i.e, who doesn't have a parallel port on the motherboard. The problem starts here, even after installin
-
Bookmark voice for the newspaper life does not show
After 6/30 (after update new version?) My voice of SWR30 is not displayed in the life diary Bookmark I lose a lot of bookmark voice I'm trying to record new voice... still do not show in log of life Please help, tks
-
the so-called important updates are installed but can not configure my laptop is unusable for the better part of an hour, what can I do?