Count the number of elements in comma seperated list of values

Hello Friends,
I have a string with comma seperated list of values say
String v = 34343,erere,ererere,sdfsdfsdfs,4454,5454,dsfsdfsfsd,fsdfsdfsdfs,dfdsfsdfsdfs,sdsfdsf,ererdsdsd45454,fsdfsdfs
Want to count how many elements are existing in this string .
Thanks/Kumar

Hi, Kumar,
REGEXP_COUNT, which Hoek used, is handy, but it only works in Oracle 11. Which version of Oracle are you using?
In any version of Oracle, you can count the commas by seeing how much the string shrinks when you remove them.
LENGTH (str) + 1 - LENGTH (REPLACE (str, ',')) Can str have multiple commas in a row? What if there's nothing between consecutive commas, or nothing by whitespace? Can str begin or end with a comma? Can str consist of nothing but commas? Depending on your answers, you may have to change things. You might want
REGEXP_COUNT ( str
             , '[^,]+'
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using.
See the forum FAQ {message:id=9360002}

Similar Messages

  • Count the number of elements in an Arraylist

    My arraylist has these elements inside it.
    [house,tom:, agent,, person,, untidy,jack:, ordered,, tidy,, tiled,roof,tom:, agent,, person,,.....]. The list continues like this.
    How can I count the number of elements after each tom upto before each jack and same for all words after jack and upto before tom? [for example in the first case there are 3 words after tom and there are 4 words after jack.]
    Thanks

    don't collapse your lists together. They represent separate data entities and should be kept separate. Go check your [other thread|http://forums.sun.com/thread.jspa?threadID=5416414&tstart=0].
    Edited by: DeltaGeek on Nov 17, 2009 11:07 AM

  • Write two functions to find the the number of elements in a linked list?

    I am trying to Write two functions to find the the number of elements in a linked list. One method using recursion and One method using a loop...
    //The linked List class is Represented here.
    public class lp {
    public int first;
    public lp rest;
    public lp(int first1, lp rest1)
    first = first1;
    rest = rest1;
    The program i wrote so far is
    import java.util.*;
    import linklist.lp;
    public class listCount{
    //loop function
    public static void show_list(lp list)
    int counter = 0;
    while(list != null)
    list = list.rest;
    counter++;
    System.out.println ("length computed with a loop:" + counter);
    //recursive function
    public static int recursive_count(lp list)
    if (list.first == null)
    return 0;
    else
    return recursive_count(list.rest) + 1;
    //main method
    public static void main (String args[])
    lp list1 = new lp(1, new lp(2, new lp(3, null)));
    show_list(list1);
    System.out.println("length computed with a recursion:" +
    recursive_count(list1));
    at the if (list.first == null) line i get the error " incomparable types:
    int and <nulltype>" I know this is a beginners error but please
    help...What should I do?

    byte, char, short, int, long, float, double, and boolean are primitives, not objects. They have no members, you cannot call methods on them, and they cannot be set to or compared with null.

  • Counting the number of elements on a page

    Does anyone know if there is any way that Illustrator can tell you the number of separate items (closed paths) on a page in Illustrator? (Rather than counting them all manually)? Any advice is appreciated.

    Open the Document Info palette, click on the flyout menu and select Objects. I think that will tell you what you need to know.
    [Edit: oops, you beat me to the draw. Why is the post time so different, though? I didn't see reply #1 when I opened the thread!]

  • How Do I Print the Number of Elements in An Array

    How do I print: "There are ____ number of elements in the array?"

    If you have a String holding a sentence, and if you split on non-empty sequences of whitespace (if the string has newlines in it, you'd probably need to pass the argument that makes \s match newlines, and for that you would probably need to use java.util.regex.Pattern -- see the docs and try some tests), when you'd get an array of Strings that were the non-whitespace parts of the original String. That makes for a reasonably good definition of the words in the sentence, although you could arguably get into some gray areas (does "isn't" count as one or two words? Does a sequence of numbers or punctuation qualify as a word?). In that case, counting the number of elements in the resulting array of String. using .length, would be a reasonable way to get the number of words in that sentence, yes.
    But rather than asking for confirmation on forums, why don't run some tests?
    import java.io.*;
    public class TestWordCount {
      public static void main(String[] argv) {
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          String line;
          while((line = in.readLine()) != null) {
            int count = // your code here, to count the words
            System.out.println("I see " + count + " words.");
        } catch (IOException e) {
          e.printStackTrace();
    }Put your word-counting code in there, then run it from the command line. Type in a sentence. See how many words it thinks it found. Does it match with your expectation, or the examples given (hopefully) with your homework assignment?

  • Count the number of business partners on a non-cumulative key figure

    Dear experts,
    I have a problem. We have an InfoCube in BW in which the Activity Journals are loaded every day. In this Activity Journals it is registered that a Material was listed (available) at a customer (value 0 or 1).
    We have a non-cumulative key figure MXW_LISTN with inflow (MXW_LISTI) and outflow (MXW_LISTO). In time this key figure receives +1 or -1 for a customer, material combination.
    I want to use MXW_LISTN in the query in a specific way. The key figure on itselve tells me how many listings there are. However, I want to know how many business partners there are with a listing.
    I was thinking about an exception aggregation on MXW_LISTN with reference characteristic 0BPARTNER and "Count <> 0". BW however refuses to do so and only lets me do simple aggregations such as AVG, MIN, MAX etc.
    Can you think with me and come with an proper solution to count the number of business partners with a listing?
    Your help is very much appreciated and rewarded!
    Best regards, Hans de Klein

    Would anything with virtual key figures be a solution? Please help me out!
    Best regards, Hans de Klein

  • Workflow to count the number of items in a list

    Hello Friends,
    I've a requirement, I need to count the number documents uploaded for a particular list item (identified by a unique Title) and if the count matches with the count stored in another list for that particular list item, bingo......I will update the status
    field to completed.
    Can anybody please help me with this. How do I do this ? Is it possible even ?
    Thank you very much in advance. :)

    Hi,
    I haven't tried this but i think you can achieve it by
    1. Add an Call HTTP activity in your workflow and make a REST call get items
    2. Use Count Items in (Dictionary variable)to get the Items counts of attachment.
    3. Then, lookup for your another list in match item count.
    Your REST query can be similar to this
    url: http://site url/_api/web/lists/getbytitle('list title')/items(item id)/AttachmentFiles/To make Rest call in SharePoint designer https://sergeluca.wordpress.com/2013/04/09/calling-the-sharepoint-2013-rest-api-from-a-sharepoint-designer-workflow/
    https://msdn.microsoft.com/en-us/library/office/dn567558%28v=office.15%29.aspx

  • Programatically count the number of files in a folder

    Hi Folks
    I need to programatically count the number of files in a given folder and return the value to a Program Unit to be included in further processing.
    Can anyone point me in the right direction. I have looked at UTL_FILE but this does not offer what I want.
    Does anyone know of an obscure package in Oracle that I could use?
    I'm using 9i in a W2K environment.
    Many thanks
    Simon Gadd

    Hi,
    following a java based solution i found somewhere on Tom Kyte's AskTom forum.
    GRANT JAVAUSERPRIV to TESTUSER;
    dbms_java.grant_permission( 'TESTUSER', 'SYS:java.io.FilePermission', 'c:\', 'read' );
    create global temporary table DIR_LIST
    ( filename varchar2(255) )
    on commit delete rows
    create or replace and compile java source named "DirList"
    as
      import java.io.*;
      import java.sql.*;
      public class DirList
        public static void getList(String directory)
                           throws SQLException
          File path = new File( directory );
          String[] list = path.list();
          String element;
          for(int i = 0; i < list.length; i++)
              element = list;
    #sql { INSERT INTO DIR_LIST (FILENAME)
    VALUES (:element) };
    create or replace procedure get_dir_list( p_directory in varchar2 )
    as language java
    name 'DirList.getList( java.lang.String )';
    exec get_dir_list( 'c:\temp' );
    select count(*) from dir_list;

  • How do I count the number of records returned in the CMIS query

    How do I count the number of records returned in the query CMIS?
    SELECT COUNT(*) FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition = \'RD_PROJETOS_EXCLUSIVOS\''}
    Euler Homero

    Hi Euler,
    interestingly enough, the reference guide for CMIS ( http://wiki.alfresco.com/wiki/CMIS_Query_Language ) that I found does not mention the COUNT function at all. On the other hand it states that: "The SELECT clause identifies which virtual columns to return in the result set. It can be either a comma-separated list of one or more queryNames of properties that are defined by queryable object types or * for all virtual columns."
    There are, however, some other posts like e.g. http://alfrescoshare.wordpress.com/2010/01/20/count-the-total-number-of-documents-in-alfresco-using-sql/ which state that they could make it working.
    Having asked in the WebCenter Portal forum, I assume that your content repository is WebCenter Content. The CMIS doc for the Content is available here: http://docs.oracle.com/cd/E23943_01/doc.1111/e15813.pdf (no COUNT there either). It does, however, mention explicitly that "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query.". This means your could rather investigate the Result Set. Note that there are also other means than CMIS how to get the requested result set (e.g. calling a search service directly via so-called RIDC).
    In the given context I am also interested what your use case is. OOTB CMIS in WebCenter Portal is used, for instance, in Content Presenter, where it is content rather than "parameters" what's displayed.

  • How to get the number of elements in DB

    Could you tell me how to get the number of elements in DB??
    My code to get the number is below, but I think it is not efficient
    DB->cursor(DB, NULL, &cursorp, 0);
    while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0)
    count++;
    --------------------------------------------------------------------------------------------------------------

    Hi,
    The most efficient way to get a count from the database is using the DB->stat API (http://docs.oracle.com/cd/E17076_02/html/api_reference/C/dbstat.html)
    The code will be something like:
            DB *dbp;
            DB_BTREE_STAT *statp;
            int ret;
            /* Print out the number of records in the database. */
            if ((ret = dbp->stat(dbp, NULL, &statp, 0)) != 0) {
                    dbp->err(dbp, ret, "DB->stat");
                    goto err1;
            printf("%s: database contains %lu records\n",
                progname, (u_long)statp->bt_ndata);
            free(statp);The code comes from the example included in the distribution at examples/c/ex_btrec.c
    If the database isn't a btree, you should update to the appropriate statistics structure and field.
    It's worth noting that retrieving the count is never a "cheap" operation. The count is not stored in the database - since doing so introduced a single point of contention that creates a bottle neck.
    Regards,
    Alex Gorrod
    Oracle Berkeley DB

  • How to count the number of Rows to be Updated before Update takes place..

    Hi all,
    I have a requirement, where i have to count the number of rows to be updated before updating it. SQL%ROWCOUNT gives the no. of rows updated ( after update takes place). How do i get to know the count of no. of rows to be updated/inserted/ deleted. I was looking for a simple solution, as above SQL%Rowcount. But i couldn't find any. I can use a Function and Return the value which will give me number of rows to be updated, But is there any Simple Logic other than this.. or any count function. Your Help is Appreciated. Thanks!

    If you really want to do this (I have no clue why you would need it), then you can piggy back on any existing pessimistic locking you may already have in place.
    However, it would require two loops through the records of which you want to know the count before you update, and a second pass to update them.
    I would really re-think the need for this, though.
    SQL> create table t0304(c number);
    Table created.
    SQL> insert into t0304 select rownum from all_objects where rownum <= 10;
    10 rows created.
    SQL> commit;
    Commit complete.
    SQL> select * from t0304;
             C
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.
    SQL> declare
      2    cursor mycursor is select * from t0304 where mod(c,2) = 0 for update;
      3    i number := 0;
      4  begin
      5    for r in mycursor loop
      6      i := i + 1;
      7    end loop;
      8    dbms_output.put_line(i);
      9    for r in mycursor loop
    10      update t0304 set c = c + 20 where current of mycursor;
    11    end loop;
    12  end;
    13  /
    5
    PL/SQL procedure successfully completed.
    SQL> commit;
    Commit complete.
    SQL> select * from t0304;
             C
             1
            22
             3
            24
             5
            26
             7
            28
             9
            30
    10 rows selected.
    SQL>Edited by: Steve Howard on Mar 4, 2011 5:57 PM

  • Determining the number of elements defined in an enum

    Hello,
    I have an enum and I want to determine the number of elements (constants) defined in this enum by source code. I know I can use reflection but I just want to know if there's an easier way.
    Thank you very much.

    Hey JavaWisdom,
    You can use the ordinal method. I made a simple example to demonstrate.
    public class NumberOfEnums {
         public static enum Enumeration {
              item1, item2, item3, item4
         public void count() {
              Enumeration[] values = Enumeration.values();
              int numElems = 0;
              for (Enumeration type : values) {
                   if (type.ordinal() > numElems) {
                        numElems = type.ordinal();
              // Correct 0 indexed numbering
              numElems += 1;
              System.out.println("numElems : " + numElems);
         public static void main(String args[]) {
              NumberOfEnums noe = new NumberOfEnums();
              noe.count();
    }Cheers,
    Cypher

  • Servlet to count the number of occurances of a particular node

    Hi
    I am looking for a servlet which will count the number of a particular node which I have supplied of an XML file.
    Can somebody please help me with this?
    Thankyou

    If you are using Xerces, after you have parsed your XML files using a DOMParser, get the document object from the parser like
    Document document = parser.getDocument();
    And then use the command getElementsByTagName("*"); // for all elements
    it will return the node list object (NodeList) which you can get the count (nodeList.getLength())

  • Is there a way to count the number of times an array moves from positive to negative?

    I have an array of values, and I need to find the number of times that the array changes signs (from positive to negative, or vice versa). In other words from a graphical standpoint, how many times a certain line crosses the x-axis. Counting the number of times the array equals zero does not help however, because the array does not always equal exactly zero when it crosses the axis (ie, the points could move from .1 to -.1).
    Thanks for you help. Feel free to email me at [email protected] I only have lv 5.1.1 so if you attach any files, they cannot be version 6.0.

    Attached is a VI showing the # of Pos and Neg numbers in an array, with 0 considered as non-Pos. It is easily modifiable to other parameters - including using the X-axis value as your compare point versus only Zero.
    This is a modified VI from LV (Separate Array.vi)
    Compare this with your other responses to find the best fit.
    Doug
    Attachments:
    arraysizesposneg.vi ‏40 KB

  • How to count the number of rows in a cube!!??

    Experts,
    I can somebody tell me how do I count the number of rows in my cube when i am using listcube???..
    Thanks
    Ashwin

    Hi,
    have a look ath this theard too
    Number of Records in Cube
    regards

Maybe you are looking for

  • Deleting DC from both client and DTR - How to ?

    Hi How to delete a DC completely both from the client and the DTR repository so that I can create it with the same DC name and package structure again. Please Help Regards Ananda

  • ITunes 9 Genius Mixes (having issues)

    I turned off Genius, turned it back on to get Genius Mixes and have not been able to actually play a Genius Mix yet! When I go to the Genius Mix icon and then try and select a Mix, I hit the Play button that appears in the middle of the 4 random cd c

  • Access to Business Rules in AAS

    We have System 9.2.0.1 and when my user logs into AAS, they cannot view the Business Rules section. what is the proper access to grant in Shared Services for them to see the Business Rules? Thanks

  • Nokia lumia 510, mobile hangs

    My mobile hangs in between calls made or received. To again use my mobile I need to take out my battery and restart the device. From the experiences of my mobile shanging(atleat it has hanged for 15 times in 1 week) I have noticed that when my intern

  • Rule for outgoing mail?

    Hello, I am currently using Entourage 2008 for mail and I have the ability there to create rules for BOTH incoming and outgoing mail items. I have a friend that is only using MAIL in Leopard and he wishes to copy items from his sent items folder up t