Count the values in a comma separated string
Hi, I have the following requirement.The entry is as below:
with test as
(select 'ABC,DEF,GHI,JKL,MNO' mystring from dual union all
select 'ABC,DEF' from dual union all
select 'JKL,MNO' from dual )
select * from test
And production is expected to be of the island belowstr cnt
'ABC' 2
'DEF' 2
'GHI' 1
'JKL' 2
'MNO' 2
I tried this query to get, as above, but the wrong exit
with test as
(select 'ABC,DEF,GHI,JKL,MNO' mystring from dual union all
select 'ABC,DEF' from dual union all
select 'JKL,MNO' from dual )
select str,count(*) from (
select regexp_substr(mystring,'[^,]+',1,level) str
from test
connect by level <= length(regexp_replace(mystring,'[^,]+')) + 1 )
group by str
Please help me to get the output as requiredThank you
SQL> with test
2 as
3 (
4 select 'ABC,DEF,GHI,JKL,MNO' mystring from dual union all
5 select 'ABC,DEF' from dual union all
6 select 'JKL,MNO' from dual
7 )
8 select str, count(*)
9 from (
10 select regexp_substr(mystring, '[^,]+', 1, level) str
11 from test
12 connect by level <= length(mystring) - length(replace(mystring, ',')) + 1
13 and mystring = prior mystring
14 and prior sys_guid() is not null
15 )
16 group
17 by str
18 order
19 by str
20 /
STR COUNT(*)
------------------- ----------
ABC 2
DEF 2
GHI 1
JKL 2
MNO 2
Tags: Database
Similar Questions
-
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>
-
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.
-
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 count the values in row
Hello
50 columns in a table are and 10 records are there. In these 10 records are not inserted not all columns (some are null values). How to find the values of The Count of Record (row).
For example
Table
P1 p2 p3 p4 p5 p6 p7 p8 p9 p10...
10 20 30 40 50
20 30
60 80
In the table below - before, how to find
the number of values in 1 record is 5
the number of values in 2nd record is 2
the number of values in 3rd record is 2
--
Thank you and best regards,
Haridecode(p1,null,0,1)+ decode(p2,null,0,1)+ decode(p3,null,0,1)+ ...
-
How to count the number of words in a string?
It is only possible by counting the number of white spaces in the string?
You can use the String.Split method to divide the string into an array using the character space as delimiter, and then check the length property of the resulting table.
-
Query to count the values in a field
I do the counts to the amount of entities in the database, I need to get the amount of registers for entities that appear
Buenas, estoy trabajando Le con plsql there is me presenta a problema, Necesito UN count the amount of looking that returns the query por entity, estoy trabajando con UN procedure y evaluando don't con UN cursor, pero no be como hacer query trabajar para devolver ese valor homes
GLOBAL ENTITY DATE TIME
====== ===== ==== ====
ENT1 5 20100318 12:00
ENT2 20 20100318 12:00
ENT3 12 20100318 12:00
CURSOR1
SELECT distinct (rp.cod_entidad),
YYYYYYYYY,
TO_DATE (to_char (sysdate, 'YYYYMMDD'), 'YYYY-mm-DD') as fecha_pago,
to_char(sysdate,'hh-mi-ss') as hora_pago
REGISTRY PR, pc product
where pc.nro_solicitud = rp.nro_solicitud
and pc.resp_2 = 'OK '.
and pc.resp_1 = 'OK '.
Published by: 862673 on 31/05/2011 10:01Hello
You don't want to then SEPARATE. Just use COUNT (*), which means "count records.
Concerning
Peter -
How to get the values of two points separated in Javascript checkbox
Hello
I want to get the values of an element of the checkbox as a form of separted from the colon as what we get in the database. For example '10:11:12 '.
When I tried to write a code like this it does not work. Please tell me where I'm wrong.
function getValues (pcheckbox) {}
cb_name = html_GetElement(pcheckbox+'_0').name;
cb_array = document.getElementByName (cb_name);
var val_str =': ';
for (i = 0; i < cb_array.length; i ++)
{
If (cb_arraychecked)
{
val_str += cb_array [i] .value + ':';
}
}
html_GetElement (P206_TEXT) .value = val_str;
}
I try to call the function getValues ('P206_CHECK');
Thank you and best regards,
Vikas KrishnaHi Vikas,
Try this-
(1) create a checkbox element called PI_CHK
(2) in the Option of the attributes of the form element, type onclick = "getValues () '"
(3) create a named text field point PI_TEXTEnter the HTML of the Page Header Section
Concerning
Paul
-
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.
-
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} } -
Change the value of type Float to String
Hello
After SQL statement gives the result as rent-.5
Select Replace ("' rent - XX", "XX", 0.5) double
How can I get the result like rent - 0.5
Thanks in advance.The use of FM (model Format) is to cut off the escape null in this case.
Here is an example
select to_char('0.5','fm0.99'), to_char('0.5','0.99') from dual
-
Count the number of items in a list separated by commas of the values
Hello friends,
I have a string with a list of so-called values comma separated
String v = 34343, erere, ererere, sdfsdfsdfs, 4454, 5454, dsfsdfsfsd, fsdfsdfsdfs, dfdsfsdfsdfs, sdsfdsf, ererdsdsd45454, Sylvie
You want to count the number of items exist in this string.
Thank you/KumarCame to my mind as well.
But I guess I'm typing too slowly, I had other options ran just a second there are tow:SQL> with t as ( 2 select '34343,erere,ererere,sdfsdfsdfs,4454,5454,dsfsdfsfsd,fsdfsdfsdfs,dfdsfsdfsdfs,sdsfdsf,e rerdsdsd45454,fsdfsdfs' str from dual 3 ) 4 -- 5 -- 6 -- 7 select length(str)-length(replace(str, ','))+1 8 from t; LENGTH(STR)-LENGTH(REPLACE(STR,','))+1 -------------------------------------- 12 SQL> with t as ( 2 select '34343,erere,ererere,sdfsdfsdfs,4454,5454,dsfsdfsfsd,fsdfsdfsdfs,dfdsfsdfsdfs,sdsfdsf,e rerdsdsd45454,fsdfsdfs' str from dual 3 ) 4 -- 5 -- 6 -- 7 select count(*) 8 from ( select regexp_substr(str, '[^,]+', 1, rownum) 9 from t 10 connect by level <= length(regexp_replace(str, '[^,]+'))+1); COUNT(*) ---------- 12
-
Analyze the values to a string and then place in the lines
Hi all
I need help here. I have a field called document_desc. Below is a sample of its contents:
Invoice: * 90104 * attachment document URL created in ArchiveLink content server. Number of
attachments: 3 Document ID (s): * 4FB6EB9040000ACA813, 4FB6EB924C0A2A813 *.
*, 4FB6EBB7000ACA813 * (s) URL :): http://xxxxxxxxxx
I need to do 2 things here:
1. I need to analyze the elements in bold. The number of values beginning with 4FB can vary. In this example, there are 3 of them, it could be one, there may be 10. However, they will be always between the ' ID (s):' and the ' URL (S):'
Invoice number (901825004) will always be only one and the same position, but can have different lengths.
2. I then need to format it so that it looks like:
Any suggestions?Invoice_Number Archive_ID 901825004 4FB6EB904C561491E1000000AC12A813 901825004 4FB6EB924C561491E1000000AC12A813 901825004 4FB6EBB74C561491E1000000AC12A813
Published by: dgouin on May 29, 2012 11:25
Published by: dgouin on May 29, 2012 11:26
Published by: dgouin on May 29, 2012 11:27
Published by: dgouin on May 29, 2012 11:27
Published by: dgouin on May 29, 2012 11:33Hello
Regular expressions a great help with this stuff:
WITH got_doc_id_list AS ( SELECT x_id , REGEXP_REPLACE ( str , '.*Invoice: *([^ ]+).*' , '\1' , 1 , 1 , 'n' ) AS invoice , REGEXP_REPLACE ( str , '.*Document ID\(s\):(.*)URL.*' , '\1' , 1 , 1 , 'n' ) AS doc_id_list FROM table_x ) , cntr AS ( SELECT LEVEL AS n FROM dual CONNECT BY LEVEL <= 10 -- Max number of doc_ids possible in one str ) SELECT d.x_id , d.invoice , TRIM ( REGEXP_SUBSTR ( d.doc_id_list , '[^,]+' , 1 , c.n ) ) AS archive_id FROM got_doc_id_list d JOIN cntr c ON c.n <= 1 + LENGTH (d.doc_id_list) - LENGTH (REPLACE (d.doc_id_list, ',')) ORDER BY x_id , c.n ;
It works Oracl 10.1 (and higher). In Oracle 11, there are new features of regular expressions which can make it a little simpler.
I guess that your data are pretty well trained. For example, I assume that there is always something (not counting the white spaces and commas) after ' ID of Document (s): "and before"URL", and that the ID never include the substring"URL"." If these assumptions are false, then the same basic approach will work, but the details are a little messier.I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Point where the above query was to produce erroneous results, and explain, using specific examples, how you get these results of these data in these places.
Always tell what version of Oracle you are using. -
How to connect the value of the input string to numeric values
Hello
I'm trying to figure out how to connect the value of unique user input string to numeric values. Basically I want the user to enter the name of a gas that I have a list for (I think I put the list of gases in a table >). Then I want to match numeric values 2 'a' and 'b', according to which gas, name of the user has set. These 'a' and 'b' values will be automatically matched with the name of the gas in a list that I put. For example, hydrogen gas has the value 3 for "a" and 4 for "b. when the user puts the ' hydrogen' name in a string constant, automatically 'a' and 'b' must be issued.» I have connect a and b to a formula
Thanks for any help
Hello
It is perhaps not exactly what you are looking for, but perhaps you could use the enumerated data type and the array of clusters of points (a, b).
Look at the VI I enclose.
-
Count the number of values selected in a form
Hello
I need to count the number of values in a form.
Here's my dump of the form:
I want to count the values encircled in red.
The number I want to, so in this case is 5.
Any suggestions?
Aegis,
Yes, good point. Here's a minor tweak:
Total: #total #.
-Carl V.
Maybe you are looking for
-
Equium A100 has recently become slow - files were changed
Hello I have a new A100 equium with windows xp edition on it (preloaded) media center. Recently, it has become slow, especially when I click on 'my computer' and my c drive, it takes forever to open the window, especially when I try and do a right cl
-
Dear, all the I 'get control topane"and after that, the scroll bars Horizontal and Vertical disappeared. I can't get these bars. Someone help me get the bars? Thank you.
-
Hello, as a year ago I bought an M6 envy, it came with windows 8 pre-installed did not bring a CD with the operating system. My problem is a few weeks ago, I had a hard drive problem, so I had to replace it. How can I recover my OS for my new hard dr
-
I read a lot of posts here and all over the internet about this problem.None of them correspond exactly to my concerns and the situation. Printer share is my main concern.The printer is connected to this computer, and I want to be able to print from
-
New Modem caused my printer to stop working
Recently I got a new modem installed and now I can't get my printer to work. I ran the troubleshooter and it still does not receive the signal from my wireless modem. How to reconnect the modem again? If I can't get the new modem to read my printer,