Count the occurance of a character in a string

What is the function to count the occurance of a character in a string.
like 'test test1 test2 test3' with in this string there are 3 white spaces.
instr will give the first one, replace will change the all... and what's for the occurance (number of white spaces, which is 3 in this case) count
Message was edited by:
gladnn

SQL> var a varchar2(25)
SQL> exec :a := 'gghhhh999jjjj'
&nbsp
PL/SQL procedure successfully completed.
&nbsp
SQL> select length(:a) - nvl(length(replace(:a,'h','')),0) from dual;
&nbsp
LENGTH(:A)-NVL(LENGTH(REPLACE(:A,'H','')),0)
                                           4Rgds.

Similar Messages

  • Count the occurence of a character in a string

    Post Author: halfpat
    CA Forum: Formula
    Hello to everyone,
    I use CR 8,0. Is anyone can tell me if this is possible:
    I have a string "12345-C-1 23456-C-2 34567-C-4", how can I count the occurence of the "C" character in this string ?Is the InStr function can help me to do this ?
    I appreciate any suggestion,
    Thanks.

    Post Author: bettername
    CA Forum: Formula
    How about measuring the length of the string, and subtracting the length of the same string where C is replaced with <nothing>?
    len("12345-C-1 23456-C-2 34567-C-4") - len(replace("12345-C-1 23456-C-2 34567-C-4" , "C", ""))

  • How to count the occurance of the data entry on OBIEE answers

    Hello guys
    I have one report that contains a column call type. In the report that I am creating, there are 200 rows in that column, but there are really just 4 types of call type; "A,B,C,D"
    So in my report it looks like this
    Call type other dim and fact
    A
    A
    A
    B
    B
    C
    D
    D
    D
    D
    Now I need to add one more column said call counts, which needs to count the occurance of each call types:
    Call type count others
    A 3
    B 2
    C 1
    D 4
    So how would I be able to achieve this on answers? I used "count" function on "count" column, but it is counting all the rows without distinguishing the call type
    Please let me know
    Thanks

    Hi,
    Looks to me like this should be a measure within the RPD rather than something you try to do at the presentation level. Any simple "# of <x>" measure will work like you describe, it should just do a simple count on something unique in the table and have an aggregation rule set, OBIEE will then automatically group by this in your report by distinct call type without you having to do anything complex.
    Regards,
    Matt

  • [Question]how to count the occurance of numbers inside the array

    im just practicing my java skill but i cant get my program work can you give me guys some idea on how to determine a number that occured more than 1 inside the array e.g i have 10 elements and inside of my offset i have
    1,2,5,4,5,6,5,8,9,5
    and what im planning to do is count the occurances of the number who occures more than 1 and for that 5 occur 3 times how my program can know that i use for loop but cant figure out how to filter the occurances of numbers inside
    my offset
    thank's

    Encephalopathic you said put - 1 instead i did - 2
    public class sample
       public static void main(String args[])
          int num[] = {2,2,2};
          int index1, count = 0, find = 0;
          for(index1 = 0; index1 < num.length - 2; index1++)
             for(int index2 = 0; index2 < num.length; index2++)
                if(num[index2]==num[index1])
                  find = num[index2];
                  count++;
             System.out.println("i found " + find + " " + count + " same number inside your offset");
    }output is:
    i found 2 3 same number inside your offset
    but another question is what if i want my program to tell the other number that occur 1 time
    like this:
    i found 1 2 same number inside your offset
    i found 2 0 same number inside your offset
    i found 1 2 same number inside your offset

  • Count the no.of of numericals from a string.

    Hi team
    I would like to count the no.of numericals from a given string.
    Ex.
    String - '1,23,567 8-9'
    The result should be 5.
    Eliminate the comma and space and hypen (-) while counting.
    1 - is 1
    23 - is 2
    567 - is 3
    8 - is 4
    9 - is 5
    Kindly help me.
    Regards
    Nakul Venkatraman

    Just one suggestion. Your solution implies single character separators:
    select length(regexp_replace('1, 23, 567 8-9','(^|\D)(\d)+','*')) str from dual
           STR
             7Small adjustment makes it separator length independent:
    select length(regexp_replace('1, 23, 567 8-9','(^|\D+)(\d)+','*')) str from dual
           STR
             5
    SQL> And it will work for 10g, but for 11g regexp_count is still simpler solution.
    SY.

  • How to check the occurrence of a character in a string

    Hello Experts,
    I have a scenario where in I have to check the occurrence of a character in a string and based on that I have to pass a data into target field.
    I was wondering whether this can achieved with mapping functions or Do I have to use an UDF.
    Thanks in advance.
    Regards
    Advit Ramesh

    Hi Advit,
    You can achieve this by using standard function indexOf from the text category. Pass in the input string and the character value you want to check for as the input.
    Standard Functions (SAP Library - SAP Exchange Infrastructure)
    If the output is -1, then the character is not in the string, otherwise it is.
    Rgds
    Eng Swee

  • Oracle function to caclulate occurance of a character in a string

    Hi All,
    I have a string lets say :
    'rahul|rahul|rahul|'
    I want to calculate the occurance of the charachter '|' which is 3.
    PS : I dont want to use connect by or reg_exp and I am using oracle 9i
    Regards
    Rahul

    Hi,
    Mac_Freak_Rahul wrote:
    looking for an oracle built-in function.Sorry, there are only a couple of hundred built-in functions. To do any of the millions of things people want, they sometimes have to combine two or more of those functions, as Paul did.
    Acutally, there is a single built-in function that does this, REGEXP_COUNT, but it was only introduced in Oracle 11.1, so it doesn't help you. The fact that they made a new function in Oracle 11 hints that the way to get the same results in earlier versions was too complicated, so don't be surprised if the best way to do this in Oracle 9 isn't as easy you'd like.
    What exactly don't you like about Paul's solution?
    Paul's solution is what I would use. If you have a reason why you can't use it, say what that reason is, and someone will help you work around it. I can think of other ways to get the same results, including returning 0 when the string doesn't contain any of the designated character, but posting them will only waste your time (not to mention mine) if they have the same problem that Paul's solution has, whatever that is.

  • Function in oracle to find number of occurances of a character in a string

    hi,
    is there any function in oracle to find the number of ocurrances of a character in a string ?
    or is there any simple way of doing the same, rather than writting many lines of code as my program is already very complex.
    Maria

    Hi Maria,
    I don't know of such a function in Oracle, but maybe you could use this:
    length(search_string) - length(replace(search_string, character_to_be_found))
    For example: select length('Hello') - length ( replace('Hello', 'l')) from dual;
    Hope this is what you're looking for
    Danny

  • How to search occurance of a character in a string

    for example in a word Mississippi, find the frequency of character S. it should be 4 as it contains four s.
    what is a code.

    Hi shri vas,
    data: result type match_result_tab,
           w_result type LINE OF  match_result_tab,
           num type c.
    FIND ALL OCCURRENCES OF 's' in 'Mississippi' results result.
    loop at result INTO w_result.
       num = num + 1.
    endloop.
    WRITE num.
    Regards,
    Seshu

  • How to count number of occurences of a character  in a string

    I want to get the count of occurences of a character within a string. Is there any function for this or should i go for a PLSQL.
    For example is the sting is "occurences" & if i search for character "c", the answer should be 3.
    Regards,
    Sunil.

    SQL> select length('occurence') - length(replace('occurence','c')) from dual;
    LENGTH('OCCURENCE')-LENGTH(REPLACE('OCCURENCE','C'))
    3

  • Count maximum occurance of charecter in a string

    HI all
    I want to know how to count the maximum number of occurrences of a character in a string
    for Eg String s = "aaabbccccccdddeeee" , here in this string the maximum occurrences charcter is "c" and its count is 5

    anilrp wrote:
    I want to know how to count the maximum number of occurrences of a character in a string
    for Eg String s = "aaabbccccccdddeeee" , here in this string the maximum occurrences charcter is "c" and its count is 5How did you do it manually (mentally)?
    Unless you are rainman I am guessing you
    counted the occurrences of each character
    then found the largest count.
    Do the same in your program.

  • 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

  • Program to count the no. of times a character occurs in a string.

    program to count the no. of times a character occurs in a string.
    Say if u have a method :- Countclass(string s,char c) then using this u should be able to count a char ' T' in the string ="TESTING".
    So it is appering 2 times.
    How to count it.

    int countChar(String s, char c) {
       int count = 0;
       for (int i=0; i<s.length(); i++) {
          if (s.charAt(i) == c)
             count++;
       return count;
    }

  • How can i count the times one TAG occurred in a XMLTYPE?

    hi all
    is there method i can use to count the times one specified TAG occurred in a XMLTYPE?
    i just konw the method getClobVal,existNode,extract,...
    but none seems can help this
    anyone can help me?

    i see
    i think i know how to use Xpath func
    but when i try the following statement on sqlplus( Release 9.2.0.4.0),it says :"the XPATH is not supportted"
    declare
    l_xml xmltype;
    num number;
    begin
    select XML_BODY into l_xml from KD_SHIMEN_SEISEI w where FILE='SMNDATA';
    --get value OK!
    num := xmltype.extract(l_xml,'/Tag1[1]/Tag2/text()').getNumberVal();
    --sum or count ,failed,Xpath not support?
    num := xmltype.extract(l_xml,'sum(/Tag1/Tag2/text())').getNumberVal();
                   DBMS_OUTPUT.PUT_LINE(num);
    end;
    can u explain this?

  • Udf to count the number of occurances

    Hello All
    I am trying to write an UDF which can count the number of occurances of charecter ' in a string and fives the result as number of occurances - 3 . For example if the char ' is present 20 times in a string , I want the result to be 17.
    Could you help me in creating this UDF please, I am a beginner to Java.
    Thank you

    Hi Sreeni ,
    I tried you code , but it has some compilation errors ,
    The cod ei used is
      //write your code here
    int count = 0;
    String str;
    for(int i=0; i=input.strlength();i++)
    if (input = '\'')
    count = count + 1;
    count = count - 3;
    str = integer.toString(count);
    return str;
    Just as you suggested ,
    for it I got these errors
    incompatible types
    found : int required: boolean
    for(int i=0; i=input.str.length();i++)
    cannot resolve symbol
    symbol : variable str
    location: class java.lang.String
    for(int i=0; i=input.str.length();i++)
    incompatible types
    found : java.lang.String
    required: boolean if (input = '\'')
    cannot resolve symbol
    symbol : variable integer
    location: class com.sap.xi.tf._MMPOFileToPayload_
    str = integer.toString(count);
    cheers

Maybe you are looking for