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/Kumar
Came 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
Tags: Database
Similar Questions
-
Find the occurrence of the word in a list separated by commas
Hello
I need to find the first occurrence of a word in a list separated by commas.
Example list:
Now I'm looking for the word: bambimonster,daemon,shark,bambi,sky
Result should be the first calculation of the event: 4
Now I'm looking for the word: Monster
Result should be the first calculation of the event: 1
Hope you can help.
TobiasHi, Tobias,.
This can be more efficient, because it does not use CONNECT BY or regular expressions. Instead of splitting the string to the level of every comma, just find the target string and count how many commas occur in front of her.
WITH got_found_pos AS ( SELECT list_txt , INSTR ( ',' || list_txt || ',' , ',bambi,' ) AS found_pos FROM table_x ) SELECT list_txt , found_pos + 1 - LENGTH ( REPLACE ( SUBSTR (list_txt, 1, found_pos) , ',' ) ) AS item_num , found_pos FROM got_found_pos WHERE found_pos > 0 ;
Delimited lsits storage is usually a bad idea in a relational database. It is best to store each item in the list on a separate line.
-
Problem using the list separated by commas with nested table element
Hello
I have a list separated by commas like this:
And want to create a function that creates a where clause clause for each element with an output like this:H23004,H24005,T7231,T8231,T9231
Here's my test function that is not working properly:UPPER('H23004') IN (UPPER(charge)) OR UPPER('H23005') IN (UPPER(charge)) OR UPPER('T7231') IN (UPPER(charge)) OR UPPER('T8231') IN (UPPER(charge)) OR UPPER('T9231') IN (UPPER(charge))
The out put looks like this:create or replace function FNC_LIST_TO_WHERE_CLAUSE(v_list in VARCHAR2) return varchar2 is -- declaration of list type TYPE batch_type IS TABLE OF pr_stamm.charge%TYPE; -- variable for Batches v_batch batch_type := batch_type('''' || replace(v_list,',',''',''') || ''''); return_script varchar2(1000); BEGIN -- loop as long as there are objects left FOR i IN v_batch.FIRST .. v_batch.LAST LOOP --DBMS_OUTPUT.PUT_LINE(offices(i)); -- create where clause IF i = 1 THEN return_script := 'UPPER(' || v_batch(i) || ') IN (UPPER(charge))'; ELSE return_script := return_script || ' OR UPPER(' || v_batch(i) || ') IN (UPPER(charge))'; END IF; END LOOP; return (return_script); end;
I don't know what I did wrong? It calculates the amount of the incorrect array element! (v_batch. Must be 5)UPPER('H23004','H24005','T7231','T8231','T9231') IN (UPPER(charge))
v_batch. FIRST = 1
v_batch. LAST = 1
Kind regards
TobiasTry this...
declare
text varchar2 (1000): = "H23004, H24005, T7231, T8231, T9231;
v_where varchar2 (1000);
Start
Text: = text | «, » ;
While instr (text, ',') <> 0
loop
v_where: = v_where | ' UPPER ("': substr (Text, 1, InStr(Text,',',1)-1) |") ' IN (UPPER (load)) OR ';
text: = substr (text, instr(text,',',1) + 1);
end loop;
v_where: = substr (v_where, 1, length (v_where)-3);
dbms_output.put_line (v_where);
end;convert it to function...
-
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)+ ...
-
REGEXP_SUBSTR for the list delimited by commas with null values
Hello
I have a column that stores a list of values comma-delimited. Some of these values in the list may be null. I'm having some trouble trying to extract the values using the REGEXP_SUBSTR function when null values are present. Here are two things I've tried:SELECT REGEXP_SUBSTR (val, '[^,]*', 1, 1) pos1 ,REGEXP_SUBSTR (val, '[^,]*', 1, 2) pos2 ,REGEXP_SUBSTR (val, '[^,]*', 1, 3) pos3 ,REGEXP_SUBSTR (val, '[^,]*', 1, 4) pos4 ,REGEXP_SUBSTR (val, '[^,]*', 1, 5) pos5 FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual); POS P POS P P --- - --- - - AAA BBB
As you can see that neither calls work correctly. Anyone know how to change the regular expression pattern to handle null values? I tried various other models but could not get anyone to work in all cases.SELECT REGEXP_SUBSTR (val, '[^,]+', 1, 1) pos1 ,REGEXP_SUBSTR (val, '[^,]+', 1, 2) pos2 ,REGEXP_SUBSTR (val, '[^,]+', 1, 3) pos3 ,REGEXP_SUBSTR (val, '[^,]+', 1, 4) pos4 ,REGEXP_SUBSTR (val, '[^,]+', 1, 5) pos5 FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual); POS POS POS POS P --- --- --- --- - AAA BBB DDD FFF
Thank you
Martin
-----
http://www.ClariFit.com
http://www.TalkApex.comHi, Martin,.
That's what you want:
SELECT RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 1), ',') pos1 ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 2), ',') pos2 ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 3), ',') pos3 ,RTRIM (REGEXP_SUBSTR (val, '[^,]*,', 1, 4), ',') pos4 ,RTRIM (REGEXP_SUBSTR (val || ',' , '[^,]*,', 1, 5), ',') pos5 FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
The query above works in Oracle 10 or 11, but in Oracle 11, you can also do it with only REGEXP_SUBSTR, without using RTRIM:
SELECT REGEXP_SUBSTR (val, '([^,]*),|$', 1, 1, NULL, 1) pos1 ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 2, NULL, 1) pos2 ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 3, NULL, 1) pos3 ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 4, NULL, 1) pos4 ,REGEXP_SUBSTR (val, '([^,]*),|$', 1, 5, NULL, 1) pos5 FROM (SELECT 'AAA,BBB,,DDD,,FFF' val FROM dual);
The problem with your first request was that he was looking for sub channels of 0 or more non-virgules. There was as a substring. consisting of 3 characters starting at position 1, he returned "AAA", as expected. Then there was an another substring, the 0 characters, starting at position 4, so it returned NULL. Then, there was a substring of 3 characters starting at position 5, so he returned 'BBB '.
The problem with your 2nd request was that he was looking for 1 or more non-virgules. 'DDD' is the 3rd this substring.
Published by: Frank Kulash, on February 16, 2012 11:36
Added Oracle 11 example -
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 -
list separated by commas - extraction of each element in an array?
Is there a quick way to make a field that contains a list of items separated by commas and put them in a table or perhaps separate variables?
for example.
a single line in the database contains the field [matches_with] and would generally contain the following elements:
rings, bracelets, necklaces
I need to be put in a variable
< cfset item1 = 'rings' >
< cfset item2 = 'bracelets' >
< cfset item3 = necklaces >
or if its more simple, put them in a table
agenda [1] = 'rings '.
point [2] = "bracelets".
point [3] = "necklaces."
There is a built-in ListToArray function to CF.
-
Transformation list separated by commas (Pages) to isolate the cells inNumbers
Hello-
have a nice ewekend arround the world!
I´ has obtained a letter of information-list discount. It s a comma-sperated pages document. I´d transform these e-mail addresses somehow to singel cell entries in a document numers. When I have a doc plain text export of pages and import it on numbers, I get a lot of lines in the table that appears. These lines are just like cells in the doc pages.
Any ideas on an automation?
Thank you!
Use find and replace to replace commas with tabs, then select, copy and paste into a table of numbers
-
Count the values in a comma separated string
Hi, I have the following requirement.
The entry is as below:
And production is expected to be of the island belowwith 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
I tried this query to get, as above, but the wrong exitstr cnt 'ABC' 2 'DEF' 2 'GHI' 1 'JKL' 2 'MNO' 2
Please help me to get the output as requiredwith 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
Thank youSQL> 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
-
List separated by commas in the rows
Hello
Data:
Row1: value, valu2, value3, value4
Row2: Value5, Value6, valu7, value8
Obligation of result:
Row1: value
Row2: value2
Row3: value3
Row4: value4
Row5: Value5
Row6: Value6
Row7: valeur7
Row8: value8
Kind regards
Ngandu
Nordine salvation,
I shook, whereas I try I posted it on the forum so that it could speed up my dev.
in any case, I got the answer in another forum of oracle. You have now the link.
WITH T AS ( Select 'val1,val2,val3' txt from dual UNION ALL select 'val65,val66,val67,val68' txt from dual ) SELECT TRIM(x.COLUMN_VALUE.EXTRACT('e/text()')) cols FROM t ,TABLE(XMLSEQUENCE(xmltype('
').EXTRACT('e/e'))) x' || REPLACE(t.txt ,',' ,' ') || ' -
Count the items in a single list or table
I use a multiple selection in MX list control. I can get a simple list of the selected items, but when I try to determine the number of items is selected, I get an empty return value.
Here is the code I use:
selectedItems = .selectedItems sprite (19)
selectedCount = selectedItems.count
After that the first call returns, selectedItems contains an array of two objects. Each object contains two field (data and label). The call of the County always returns void. I tried selectedItems.count () which indicates that both parameters are mandatory and another every permutation I can think.
What is the secret to count the number of items in a list?
Your problem is perhaps that the returned object is an object AS and not a list (jargon). What happens if you try
selectedCount = selectedItems.length
-
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.
-
SQL query: How to list the values in the IN operator
Hello
I'm going through a list of values to the location of < > in < list >
I don't want to use dynamic cursors (REF CURSOR). Is this possible using Oracle SQL?
Please let me know.
My program:
DECLARE
...
list_of_ids: = '10, 20, 30';
...
SELECT MAX (sal) IN the max_sal FROM Employees WHERE emp_id IN (list_of_ids);
...
END;
/
Thanks in advance,
NikoYou do not want a list separated by commas. You want to move a collection. Then
CREATE TYPE num_tbl AS TABLE OF NUMBER; DECLARE l_list_of_ids num_tbl := num_tbl( 10, 20, 30 ); BEGIN ... SELECT max(sal) INTO max_sal FROM employee WHERE emp_id IN (SELECT * FROM TABLE( l_list_of_ids )); ... END; /
Justin
-
How to set the value of the box check the plug-in in session state using a DA
I want to click on the box (plug version) and set (Y or N) in session state without submitting the page. Is it possible to do it in a dynamic action? or a code in the ? The HTML Form element attributes
I tried the code proposed to
using AJAX, but can't make it work.
I also tried the following code, but doesn't seem to work for checkboxes.
<script language="JavaScript" type="text/javascript"> function f_setItem (pItem) { //alert('running fsetItem'); var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=dummy',&APP_PAGE_ID.); get.add(pItem,$x(pItem).value) gReturn = get.get(); get = null; } </script>
More modern solutions using a DA?
Should I use an event 'onCheck' or 'onchange '?
Thanks in advance
PaulP
APEX V4.2.3
DB EA 11.2
APEX listener V2.0.5.287.04.27
13 blue-gray theme
IE9.0.8112
FF26.0
Paul, in fact, you can use a dynamic Action.
Say your question change event, say P1_CHECKBOX.
So here's the clincher.
Action: execute the PL/SQL Code
PL/SQL code:
Start
null;
end;
Page to submit items: P1_CHECKBOX
That's all.
Read the help on the elements of Page to submit
«Specify a list separated by commas of the elements of the page that will be submitted to the server and therefore available for use in your 'code PL/SQL'.»
Kofi
-
Export data from Oracle table to a .csv file by putting a condition on the value of a column
Hello gurus,
I have the following data in my table
ROWID name version date
1 oracle 11.1 20/12/2013
Java 2 7 12/10/2011
1 oracle 12.1 28/12/2013
1 oracle 10.2 12/06/2010
Now I need a general sql/plsql code who wrote the columns with a specific value to the rowid.
My output should look like
1,Oracle,11.1,12/20/2013
1,Oracle,12.1,12/28/2013
1,Oracle,10.2,06/12/2010
Here, I want to pass the value as a parameter dynamically
Can someone help me with the sql/plsql.
Hello
If you use the IN operator:
Select rowid_col
|| ',' || name_col
|| ',' || version_col
|| ',' || To_char (date_col, 'HH24:MI:SS of Mon-DD-YYYY') AS csv_text
from your_table
where rowid_col IN (& input_values);
then & input_values can be a unique number (e.g. 1) or a list separated by commas (for example, 1,2,3) numbers. Don't put NO space around the comma.
Maybe you are looking for
-
Where can I find the analysis created by the new dashboard interest?
This seems like it should be obvious, but I simply don't think this. The page says add-on the add-on includes a new homepage, so I tried to reset the home page in the preferences. He takes me to the home page of Firefox, but it does not seem a «dashb
-
Lost icon of report of trusteer, unable to find an answer on the Web site here.
I've just updated to Version 6 of Firefox, I lost the Trusteer report icon located on the tool bar, the same thing happened when I downloaded Version 5, I was hoping that my information was still available in my messages Inbox when I logged in Mozill
-
Account reset virtual store - 30687 account
After the upgrade and register virtualstore there is only a blank screen in the virtualstore.So I need support or account reset, if this can help.My account 30687Firmware E_1.100
-
Search the Web selected words in a Web page
HelloIs it possible to remove the small box (arrow in the blue box) when I select a Word. I know that I can search by word selected with right click, but before firefox 3.6.10 there is this blue box that allows me to choose a search engine per click.
-
Pavillion g7 notebook: 8 not found windows system image
I tried to create a dual-boot system, and it failed. So, I ordered the hp recovery DVD and recovered my system windows 8. I had created a system image recovery composed of 6 DVDs. I wanted to restore my pc using the system image, I created, but any m