Count a Charapter in a string

Hi All,
There is a oracle function that count a specific character in a string?
Thank's in advance
Fabio

You need to modify the algorithm slighty in order to work correctly when the string consists only of the search pattern.
SQL> var a varchar2(40)
SQL> exec :a := 'xxx';
PL/SQL procedure successfully completed.
SQL>
SQL> select length(:a) - length(replace(:a,'x','')) count_of_g from dual;
COUNT_OF_G
SQL>
SQL> select length(:a) - nvl(length(replace(:a,'x','')), 0) count_of_g from dual;
COUNT_OF_G
         3
SQL>

Similar Messages

  • How to count a occurence of a string in file

    import java.util.*;
    import java.io.*;
    class Count
    public static void main(String args[ ] )throws Exception
         FileReader fr=new FileReader("d:\\compfetch\\clean\\first.txt");
         BufferedReader br=new BufferedReader(fr);
         StringBuffer sb=new StringBuffer();
         while((s=br.readLine())!=null)
              sb.append(s);
         s=sb.toString();
    Vector v= new Vector();
         v.addElement("job");
         v.addElement("jobs");
         v.addElement("career");
         v.addElement("careers");
         v.addElement("vacancy");
         v.addElement("vacancies");
         v.addElement("opportunity");
         v.addElement("openings");
         v.addElement("posting");
         v.addElement("postings");
         v.addElement("opportunities");
         v.addElement("placement");
         v.addElement("placements");
         v.addElement("job");
         v.addElement("job");
         Enumeration vEnum=v.elements();
         while(vEnum.hasMoreElements())
              System.out.println(vEnum.nextElement());
    I need to count the occurence of each string given in the vector from the text file.I have the file and the vector.How do i compare the vector and textfile ,so that i can count the occurence of eachString in the vector with the text file.The text file may contain any of the words given in the vector.If found ,a count shld be made for each string .
    regards,
    koel

    Try this code:
    import java.util.*;
    import java.io.*;
    class Count
    public static void main(String args[ ] )throws Exception
         FileReader     fr = new FileReader("c.c");
         BufferedReader br = new BufferedReader(fr);
         StringBuffer   sb = new StringBuffer();
         String         s;
         while((s=br.readLine())!=null)
              sb.append(s);
         s=sb.toString();
         Vector v= new Vector();
         v.addElement("job");
         v.addElement("jobs");
         v.addElement("career");
         v.addElement("careers");
         v.addElement("vacancy");
         v.addElement("vacancies");
         v.addElement("opportunity");
         v.addElement("openings");
         v.addElement("posting");
         v.addElement("postings");
         v.addElement("opportunities");
         v.addElement("placement");
         v.addElement("placements");
         Enumeration vEnum=v.elements();
         while(vEnum.hasMoreElements())
              String l = (String)vEnum.nextElement();
              int    a = 0;
              int    p = s.indexOf(l,a);
              int    c = 0;
              while (p != -1)
                   c = c + 1;
                   a = a + l.length() + p;
                   p = s.indexOf(l,a);
              System.out.println(l+"  "+c);
    }

  • [svn:fx-trunk] 13501: Bug: BLZ447 - AMF3 Deserialization: Wrongly counted reference ID of duplicated String when in the same message there are Strings with only wildcards

    Revision: 13501
    Revision: 13501
    Author:   [email protected]
    Date:     2010-01-14 06:01:23 -0800 (Thu, 14 Jan 2010)
    Log Message:
    Bug: BLZ447 - AMF3 Deserialization: Wrongly counted reference ID of duplicated String when in the same message there are Strings with only wildcards
    QA: Yes - please keep an eye on AMFX (HTTPChannel) tests.
    Doc: No
    Checkintests: Pass - except the usual 4-5 tests that time out on my machine.
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/rpc/src/mx/messaging/channels/amfx/AMFXDecoder.as

    Dear Pallavi,
    Very useful post!
    I am looking for similar accelerators for
    Software Inventory Accelerator
    Hardware Inventory Accelerator
    Interfaces Inventory
    Customization Assessment Accelerator
    Sizing Tool
    Which helps us to come up with the relevant Bill of Matetials for every area mentioned above, and the ones which I dont know...
    Request help on such accelerators... Any clues?
    Any reply, help is highly appreciated.
    Regards
    Manish Madhav

  • Count of occurences of a string senetence in 9i?

    Hi All,
    Is there an easy way using SQL to count the number of occrences of a string in a sentence? Dont want to use pl/sql if i can help it, maybe im missing an easy function?. Im using 9i rel2.
    eg find the count of ':' in the below string
    a:b:c:d: should return 4. (the separtor being : included on the end)
    a:b: should return 2
    and so on?
    Kind Regards
    Satnam

    SQL> SELECT a-LENGTH(REPLACE(SUBSTR(p,1,a),':',''))
      2    FROM
      3  (SELECT INSTR('a:b:c:d:e:',':',-1,1) a
      4         ,'a:b:c:d:e:' p
      5    FROM dual);
    A-LENGTH(REPLACE(SUBSTR(P,1,A),':',''))
                                          5Khurram

  • How to count occurences of a certain string in incoming real-time data? Also displaying RTC data. Current VI included

    I use LabView student Express 7 on a Windows XP system.
    Time-frame: we are doing final integrations for our balloon experiment today. We just got told that the press wants to view real-time data, which we haven't programmed for. I need help to get a working VI at the latest by 25.02.2004 before 0800(morning) (GMT+1).
    Note on license
    It is a student balloon flight, and the data will not be used in scientific work, so the I am not breaking any license agreements (I hope).
    Problem synopsis:
    The balloon continually transmits data at 9600baud. The data is a semi-repeating header followed by a constant lenght data-package arranged like this:
    BEXUS[h][m][s]BEXUS[h][m][s]
    [Raw binary data, 7channels*8sub-channels*8bits]
    What the groundstation is doing right now:
    Take all incomming data and save (append) the data to a file without any data-handling. (We figured we would go post-processing).
    What I need to change in less than 24 hours:
    - Add a "package" counter
    - Add a display of the clock data (RTC)
    How I planned to implement the changes:
    -RTC display:
    The RTC data is in BCD format, since that means that if you look at the data as hex numbers, you get the hours and minutes and seconds out in "clear text". That is 12 hours is 0x12hex. I figured that I can do a match pattern BEXUS and pass the "after substring" to another match pattern BEXUS from which I feed the "before substring" to a type-cast VI (casting string to u8) and displaying that, which should give me a display of "123000" for the time 12:30:00... I couldn't get it to work at all when I tried out the supplied "beta" vi.
    - Package counter:
    Counting how many BEXUS that gets detected and dividing by 2. I don't know how to do this. I've looked on the forum (a good thread on the problem: "how do I count the number of *'s in a string") but these use either loops or arrays... and I'm not sure how this works when I'm getting the data in at realtime. I cant make an array and then count it, since then the array would grow fast and possibly interfere with saving of the data??? Saving the data is critical.. without that file we cant do post-processing.
    Since my time is so limited (I'm not even supposed to do the groundstation software but they called on me in the last minute because no-one else had time/wanted too/could do it) I hope that you could make an exception and provide me with working VI's (based on the one I have attached) so that I can show something to the press! (Free comercial for NI!! Since the student version shows the National Instruments water-mark on all VI's!!! Possible TV time!!)
    Thanks!
    PS: even if you are to late (after 25) post anyway!
    Why:
    -I can learn from it
    -the launch might be delayed due to weather conditions
    -others might find it amusing!
    Thanks again!
    Attachments:
    BexusII_groundstation.vi ‏46 KB

    I have a valid example data file attached to this thread.
    If you open BEXTEST.bin in a hex-editor of your choice, you'll see the BEXUS as 42 45 58 55 53 and then the time as 00 28 09 etc.
    I couldn't get Joe Guo's VI to work. It doesn't count packages correctly, and the time is not displayed correctly either.
    The file was saved using a straight save to file VI.
    The data is from actual launching area tests performed a few mintues ago. The time displayed is "On time" e.g. how long the gondola has been powered up.
    I have a spare T-junction, so I can hook into the balloon real-time data as we fly, in case anyone care to see if they can figure out why the latest version of Joe Guo's program is not displaying correctly.
    I will monitor this
    thread during and after flight to see if anyone can make it in time!
    Thanks for the great effort!!
    Attachments:
    bextest.bin ‏53 KB

  • Count of character in a string

    Hi,
    Here is a string.
    Str = 'test,123,1-Jan-2008',sql,oracle,test,date
    Can we count the number of commas(,) in the above string without passing it to any loop? I want to use replace/translate and length for this purpose.
    Regards,
    Ritesh

    SQL> var a varchar2(500)
    SQL> exec :a := '''test,123,1-Jan-2008'',sql,oracle,test,date'
    PL/SQL procedure successfully completed.
    SQL> print a
    A
    'test,123,1-Jan-2008',sql,oracle,test,date
    SQL> select length(:a)-length(replace(:a,',')) comma_count
      2    from dual
      3  /
    COMMA_COUNT
              6

  • Counting particular character in a string

    Hi all
    how can we count the number of characters in a perticular string in simple SQL statement
    example
    how many commas are there in this string 'a,b,s,d,e,f,g,h'

    select length('a,b,c,d,e')-length(replace('a,b,c,d,e',','))
    from dual

  • Counting the character in a string

    How to find the number of repeated characters in a string
    example- 'RAJA' In this string how many 'A' are there

    A beautiful query posted by a guru in this forum long time ago.
    SQL> set line 1000
    SQL> l
      1     SELECT ename
      2          , Letter_repetition
      3          , COUNT(*)repetition_count
      4     FROM ( SELECT ename
      5                   , Letter_repetition
      6                FROM emp
      7               MODEL
      8                     RETURN UPDATED ROWS
      9                     PARTITION BY (ename)
    10                     DIMENSION BY (0 i)
    11                     MEASURES (ename Letter_repetition)
    12                     ( Letter_repetition[FOR i FROM 1 TO
    13                                         length(Letter_repetition[0])
    14                                         INCREMENT 1] = SUBSTR(Letter_repetition[0],CV(i),1)
    15                     )
    16             )--End of FROM clause
    17      GROUP BY ename
    18          , Letter_repetition
    19*    HAVING COUNT(*) > 1
    SQL> /
    ENAME                               LETTER_REPETITION                   REPETITION_COUNT
    SCOTT                               T                                                  2
    TURNER                              R                                                  2
    ALLEN                               L                                                  2
    MILLER                              L                                                  2
    ADAMS                               A                                                  2
    SQL>

  • Getting count of occurances of a string in a column value

    Hi,
    Is there a way to get the number of occurences of a string in a single column value?
    Example:
    CREATE TABLE STRING_CNT(X VARCHAR2(100));
    INSERT INTO STRING_CNT(X) VALUES('OracleXXOracleXXOracleXXOracle');
    Commit;
    Now the string 'Oracle' is repeated 4 times in the inserted value. I would like to get this count using SQL.Can some one tell me how to get this?
    I was asked this interesting question in an interview today.

    hi<br>
    u can get the occurrence of a string in text as
    follow<br>
    >
    SELECT (LENGTH(x)-LENGTH(REPLACE(x,'Oracle', ' ' )))<br>
    / LENGTH('Oracle') as<br>
    Occurrence FROM STRING_CNT;<br><br>
    <br>
    Are you sure...?<br>
    <br>
    <br>
    SQL> with STRING_CNT as
      2  (select '1.Oracle2.Oracle3.' x
      3  from dual)
      4  SELECT (LENGTH(x)-LENGTH(REPLACE(x,'Oracle', ' ' ))) / LENGTH('Oracle') as Occurrence
      5  FROM STRING_CNT;
    OCCURRENCE
    1.66666667
    <br>
    Sidenote: Please give a try before posting..<br>
    And you are posting a wrong solution after a TESTED right solution posted hours before..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Count a character within a string

    Give a string, what function can I use to count how many a particular character in the string. For example:
    "abc;def;ghi;xyz"
    I want to find out how many ";" in this string.
    Thank you

    And of course, if the researched character is not in the given string, then you'll return null, to return 0, you'll need a NVL.even if it is in the string you might need a nvl in Vamsi Kasina's solution:
    SQL>  select length (';') - length (replace (';', ';')) cnts
      from dual
          CNTS
    1 row selected.Better:
    SQL>  select nvl(length (';'),0) - nvl(length (replace (';', ';')),0) cnts
      from dual
          CNTS
             1

  • Count of characters in a string

    Hi all,
    Is there any way to find the repeating characters in the string like 'L' in the example Hello ..
    Thanks in advance,
    Nalla !
    Message was edited by: Nalla
    Nalla (Nallasivam)

    test@ORA10G>
    test@ORA10G> with t as (
      2    select 'hello' as str from dual union all
      3    select 'abracadabra' from dual union all
      4    select 'the quick brown fox jumps over the lazy dog' from dual union all
      5    select 'abcdefghijklmnopqrstuvwxyz' from dual union all
      6    select 'facetious' from dual)
      7  --
      8  select
      9    str
    10  from t
    11  where (
    12    length(str) - length(replace(lower(str),'a')) > 1 or
    13    length(str) - length(replace(lower(str),'b')) > 1 or
    14    length(str) - length(replace(lower(str),'c')) > 1 or
    15    length(str) - length(replace(lower(str),'d')) > 1 or
    16    length(str) - length(replace(lower(str),'e')) > 1 or
    17    length(str) - length(replace(lower(str),'f')) > 1 or
    18    length(str) - length(replace(lower(str),'g')) > 1 or
    19    length(str) - length(replace(lower(str),'h')) > 1 or
    20    length(str) - length(replace(lower(str),'i')) > 1 or
    21    length(str) - length(replace(lower(str),'j')) > 1 or
    22    length(str) - length(replace(lower(str),'k')) > 1 or
    23    length(str) - length(replace(lower(str),'l')) > 1 or
    24    length(str) - length(replace(lower(str),'m')) > 1 or
    25    length(str) - length(replace(lower(str),'n')) > 1 or
    26    length(str) - length(replace(lower(str),'o')) > 1 or
    27    length(str) - length(replace(lower(str),'p')) > 1 or
    28    length(str) - length(replace(lower(str),'q')) > 1 or
    29    length(str) - length(replace(lower(str),'r')) > 1 or
    30    length(str) - length(replace(lower(str),'s')) > 1 or
    31    length(str) - length(replace(lower(str),'t')) > 1 or
    32    length(str) - length(replace(lower(str),'u')) > 1 or
    33    length(str) - length(replace(lower(str),'v')) > 1 or
    34    length(str) - length(replace(lower(str),'w')) > 1 or
    35    length(str) - length(replace(lower(str),'x')) > 1 or
    36    length(str) - length(replace(lower(str),'y')) > 1 or
    37    length(str) - length(replace(lower(str),'z')) > 1
    38  );
    STR
    hello
    abracadabra
    the quick brown fox jumps over the lazy dog
    3 rows selected.
    test@ORA10G>
    test@ORA10G>pratz

  • Count of words in a string

    i have a string "hai oracle tech team"
    i want to calculate the number of words in it
    i.e. it should return 4
    how to do it

    Haven't you answers in your duplicate thread from the last week ?
    Re: how to calculate the number of words in a column
    Nicolas.

  • Count of occurrences of ' " ' in string

    Hi,
    The answer to this is probably really obvious, but I can't work it out!...
    I have a field in a table that holds a string of characters such as:
    a"b"c"d"e"f
    How can I return the number of occurrences of " (double quotes, not two singles) for each row?
    Regards
    Carl

    Yeah, it was just new thing.
    An other way working on 9i :
    SQL> select nvl(length(trim(translate(mystr,translate(mystr,'" ', ' '),' '))),0) nb_double_quotes
      2  from (select 'a"b"c"d"e"f' mystr from dual);
    NB_DOUBLE_QUOTES
                   5
    SQL> select nvl(length(trim(translate(mystr,translate(mystr,'" ', ' '),' '))),0) nb_double_quotes
      2  from (select 'a' mystr from dual);
    NB_DOUBLE_QUOTES
                   0Nicolas.

  • Count occurences of subsring in string

    I am using cfhttp to return an hmtl table. I would like to
    "count' the number of "<tr>" tags in the cfhttp.filecontent
    variable I do not nessarily want to loop over it... is there a way
    to do this?

    If your <tr> has white space on each side, you could
    use the ListValueCountNoCase( ) function (
    http://livedocs.macromedia.com/coldfusion/5.0/CFML_Reference/Functions155.htm#1108281)
    Use a space as the list delimiter.

  • Count occurence of words in string

    hi guys. i need some help.
    my problem is. i have a string, and want to know how many times each word appears in it, and print out only the word that appear more than 2 times.
    has any one an idea of how this is possible?

    There are many solutions, but here is the outline of one possible method.
    1) Split your string in words with the StringTokenizer class
    2) Create a HashMap
    3) look up your word in the hash map
    4a) If the word is not in the hashmap, create a new entry in the HashMap, where the key is your word from the original string, and the Value is (new Integer(1))
    4b) if the word is already in the hashmap, get the value from the hashmap, add one to it, then put the new Integer value in the hashmap
    5) for each value in the hashmap, print out the key , if the value is an Integer > 1
    With any luck, that will help you

Maybe you are looking for

  • UNABLE TO WAKE A SLEEPING MAC MINI - HELP APPRECIATED

    Dear All, We've just got a new (2010) MacMini which is being used as a central media server, and being administered remotely via ARD 3.3.2. The only problem we seem to be having is that once the Mac Mini has put itself to sleep we're unable to wake t

  • Cisco RV042 - Dual Wan Load Balancing - Secure Site (HTTPS) Trouble

    PID VID : RV042 V03 Firmware Version : v4.0.0.07-tm (Aug 19 2010 19:19:50) Ever since I setup my RV042 with load balancing using the Dual Wan system I have had trouble staying connected to some secure sites. After doing some searching I found that th

  • User folder resets

    I accidentally changed the name on my home folder. Of course, now all my files are under an alias. But the strange thing is that can get anything back into my home folder. Every time I shut down or restart , the system resets everything on the OS, li

  • Translation Mayhem

    Hi everyone, I'm new to APEX and as such, I have a few basic questions for you guys (and girls!). The language is based on the browser's setting. Let's start with APEX_LANG.MESSAGE. The primary language of my app is french. I created my TRADC_DAY tra

  • SAP SD CIN Query-1

    Hi Experts Pls help me with the following problem. whts the functional/ technical working difference between updating RG1 and extracting it? (J1I5, J2I5). how to differentiate the update and extract RG1 register activity? Pls reply asap Deepak