Calculate the number of times a character appears in a string

Please help.
Is there a way to count a number of occurences of a particular character in a string? e.g. If you have 'DATABASE' as a string, can you calculate the number of times 'A' occurs in it? The answer is supposed to be 3, but can you calculate it in Oracle?
Thanks in advance.

Re: Any built-ins for occurance

Similar Messages

  • Find the Number of times a '¯'character appears in a string.

    Hi,
    In my staging table I am having data like below
    ABL¯ABL¯0¯0¯ABL¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ 
    ABL¯ABQ¯480¯825¯DLS¯AMA¯ABQ¯ ¯ ¯ ¯ ¯ ¯ ¯ 
    ABL¯ACD¯808¯1255¯DLS¯ELP¯TCS¯PHX¯ACD¯ ¯ ¯ ¯ ¯ 
    ABL¯ADE¯1256¯471¯DLS¯AMA¯ABQ¯LSV¯ADE¯ ¯ ¯ ¯ ¯ 
    ABL¯AFT¯1140¯1744¯DLS¯LAX¯FON¯AFT¯ ¯ ¯ ¯ ¯ ¯ 
    ABL¯AHM¯1178¯1637¯DLS¯LAX¯AHM¯ ¯ ¯ ¯ ¯ ¯ ¯ 
    ABL¯ALB¯1769¯1825¯DLS¯WIL¯ALB¯ ¯ ¯ ¯ ¯ ¯ ¯ 
    ABL¯ALE¯1041¯1150¯DLS¯ALE¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯
    Now I want to find the Number of times a '¯'character appears in a string.
    I should get output 14
    thanks & regards,
    Vipin Jha
    Thankx & regards, Vipin jha MCP

    Hi Vipin,
    You can try below sql code also
    code:-  len(data)-len(replace(data,'¯','')) -(len(data)-len(replace(data,' ','')))
    select data,len(data)-len(replace(data,'¯','')) -(len(data)-len(replace(data,' ',''))) CountofCharacter from
    select 'ABL¯ABL¯0¯0¯ABL¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ ' data
    UNION
    SELECT 'ABL¯ABQ¯480¯825¯DLS¯AMA¯ABQ¯ ¯ ¯ ¯ ¯ ¯ ¯ '
    UNION
    SELECT 'ABL¯ACD¯808¯1255¯DLS¯ELP¯TCS¯PHX¯ACD¯ ¯ ¯ ¯ ¯ '
    UNION
    SELECT 'ABL¯ADE¯1256¯471¯DLS¯AMA¯ABQ¯LSV¯ADE¯ ¯ ¯ ¯ ¯ '
    UNION
    SELECT 'ABL¯AFT¯1140¯1744¯DLS¯LAX¯FON¯AFT¯ ¯ ¯ ¯ ¯ ¯ '
    UNION
    SELECT 'ABL¯AHM¯1178¯1637¯DLS¯LAX¯AHM¯ ¯ ¯ ¯ ¯ ¯ ¯ '
    UNION
    SELECT 'ABL¯ALB¯1769¯1825¯DLS¯WIL¯ALB¯ ¯ ¯ ¯ ¯ ¯ ¯ '
    UNION
    SELECT 'ABL¯ALE¯1041¯1150¯DLS¯ALE¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯'
    ) t
    Thanks
    Prasad

  • Count the number of times a character is in a string using pl/sql

    I need to count the number of times ":" appers in the string ":XXX:CCC:BBB:".
    I have sound some solution using SQL but I do not want the context switch.
    Also I am on 10g so I can not use REGEXP_COUNT.
    Any help would be great.

    Hi,
    length(REGEXP_REPLACE(':XXX:CCC:BBB:','[[:alnum:]]'))counts all kinds of punctuation, spaces, etc., not just colons. Change any (or all) of the colons to periods and it will still return 4. Use '[^:]' instead of '[[:alnum:]]' if you really want to count just colons.
    Also, "SELECT ... FROM dual" is usually needed only in SQL*Plus or similar front end tools. In PL/SQL, you can call functions without a query, like this:
    x := NVL (LENGTH (REGEXP_REPLACE (txt, '[^:]')), 0);

  • 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 do I count the number of times a word appears in a column?

    What I have is a spreadsheet logging work history. Let's say the work location is "office", "home", or "travel" and I want to have a separate cell in another table for totals, count up the number of time each appears in the data for the year. So it would look like this:
    Date
    Location
    sept 1
    office
    sept 2
    home
    sept 3
    home
    sept 4
    travel
    sept 5
    office
    sept 6
    office
    sept 7
    office
    sept 8
    travel
    sept 9
    home
    sept 10
    office
    Totals
    Days
    10
    Office
    5
    Home
    3
    Travel
    2
    I just can't figure out how to develop the formula to put in the Totals column to make it work this way. If you can help me achieve this I'd really appreciate it!

    Hi SpartanAntarctican,
    Table 1 to record your locations
    Date
    Location
    sept 1
    office
    sept 2
    home
    sept 3
    home
    sept 4
    travel
    sept 5
    office
    sept 6
    office
    sept 7
    office
    sept 8
    travel
    sept 9
    home
    sept 10
    office
    Table 2 to sum your locations
    Totals
    Days
    10
    Office
    5
    Home
    3
    Travel
    2
    In Table 2 the formula in B2
    =ROWS(Table 1::A)−1
    Minus 1 because there is a Header Row in Table 1.
    In Table 2 the formula in B3 (and Fill Down)
    =COUNTIF(Table 1::B,A3)
    You can check this by adding 5 + 3 + 2 to arrive at 10
    Or maybe delete Row 2 put the Days calculation into a Footer Row in Table 2
    =SUM(B) .
    Regards,
    Ian.

  • How to calculate the number of times an user has accesed a BEx report

    Hi Experts,
    We have number of reports in our BW portal and users logon to the portal and run the reports.
    How do we count the number of times each user has logged in and ran each report.
    Kindly advice.
    Thanks,
    Sai

    Hi Sai:
    I think you can use BI statistics information, which could provide you more detail information.
    You can follow the document
    http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/90080703-4331-2a10-cd98-9c1e95acdea0
    Regards,
    Louis Lu

  • Find the number of times a word appears

    In Google Chrome find/search (ctrl+F) it will tell you how many times the word you are finding appears.
    In Firefox I know you can find things (also ctrl+F) but is there any way in which you can find how many times that word appears, like in Chrome.

    Any help please, anyone?

  • How to count the number of instances a record appears in a string

    I have a move that imports Name, Department and Site from an
    external CSV file, this part I managed to get working after many
    weeks. I would like to be able to count the number of instances of
    a specific Site “Glasgow” appears in the String. This
    way I know how many lines to set.
    Also can you add Dynamic text to a rollover button? I can get
    the the text to display on the root but not on a button.
    I am new to programming and Flash so apologies in
    advance.

    Those which took time to read carefully *_iWork Formulas and Functions User Guide_* are aware of the availability of wildcard characters.
    =COUNTIFI(range;"=text")
    will do the trick.
    Yvan KOENIG (VALLAURIS, France) lundi 26 avril 2010 17:36:34

  • Count the number of instances a record appears in a string

    I have a move that imports Name, Department and Site from an
    external CSV file, this part I managed to get working after many
    weeks. I would like to be able to count the number of instances of
    a specific Site “Glasgow” appears in the String. This
    way I know how many lines to set.
    Also can you add Dynamic text to a rollover button? I can get
    the the text to display on the root but not on a button.
    I am new to programming and Flash so apologies in
    advance.

    Hi,
    length(REGEXP_REPLACE(':XXX:CCC:BBB:','[[:alnum:]]'))counts all kinds of punctuation, spaces, etc., not just colons. Change any (or all) of the colons to periods and it will still return 4. Use '[^:]' instead of '[[:alnum:]]' if you really want to count just colons.
    Also, "SELECT ... FROM dual" is usually needed only in SQL*Plus or similar front end tools. In PL/SQL, you can call functions without a query, like this:
    x := NVL (LENGTH (REGEXP_REPLACE (txt, '[^:]')), 0);

  • Count number of times each char appears??

    Hi! I'm trying to figure out, how to count the number of times ech character appears in the text using ascii code??

    Go the text character-by-character, and count each character. It's that simple.
    The only remotely hard part is holding your character counters. You could use a Map.
    But if you know that the characters are always going to be ASCII, then there's only going to be 128 of them.
    So an array of int with 128 elements should be sufficient.
    Those are more than enough hints. Go do your homework now.

  • Calculate number of times a name appears within a date range.

    Hello,
    I am actually using the iPad version but I assume the formula will be the same. Say I have a date in column A and a list of names in column B. What would the formula be to calculate the number of times a specific name appears in a date range.
    Thank you

    If C2 = the minimum date of the range
    C3= the maximum date of the range
    and you are looking for John as the name
    =COUNTIFS($A,">="&C2,$A,"<="&C3,B,"john")
    which counts cells where A>=the min date and A<=the max date and B="john"

  • Generate numbers in incremental order, the number of times condition met?

    I have tried explaining my problem here also.
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=31&t=007531&p=1
    But trying to put in other words now.
    I have a NO tag which appears many times in xml. and alwyas have some random numbers displaying.
    output looks something similar to this
    something......<NO>1</NO>
    something......<NO>1</NO>
    something......<NO>2</NO>
    something......<NO>1</NO>
    something......<NO>3</NO>
    something......<NO>1</NO>
    something......<NO>5</NO>
    something......<NO>1</NO>
    something......<NO>1</NO>
    something...... & so on.
    Now instead of these numbers coming in this order i prefer to display in final output file as
    1 2 3 4 5 .................... n
    Is it possible in any ways using xslt.
    DO we need to ignore the values given in input file and then generate output values for same.
    it can be like the number of times NO tag appears in xml, it should start from 1 and keep increasing value by 1, until NO tag finishes appearance.
    But next time when other xml transforms it again should be able to start from 1 till n.
    is there a possibility of using java code for this situation or xslt is capaable enough to handle this.
    Thanks
    VJ

    I'm guessing you are looking for something like this. I used a pull approach but it could be done with a push (xsl:for-each).
    Sample XML
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
         <NO>1</NO>
         <NO>1</NO>
         <NO>2</NO>
         <NO>1</NO>
         <NO>3</NO>
         <NO>1</NO>
         <NO>5</NO>
         <NO>1</NO>
         <NO>1</NO>
    </root>
    Sample XSLT
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output method="xml" version="1.0" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
         <xsl:template match="root">
              <output>
                   <xsl:apply-templates select="NO"/>
              </output>
         </xsl:template>
         <xsl:template match="NO">
              <row>
                   <xsl:value-of select="position()"/>
              </row>
         </xsl:template>
    </xsl:stylesheet>
    Sample Output
    <output>
         <row>1</row>
         <row>2</row>
         <row>3</row>
         <row>4</row>
         <row>5</row>
         <row>6</row>
         <row>7</row>
         <row>8</row>
         <row>9</row>
    </output>

  • Return amount of times a character is in a string?

    Hello, quick question. As the title says, how can i return the amount of times a character is in a string? character such as 'a', 'b', etc. Thank you all, appreciate it!

    thank you for your help! so would this be correct? (s is the string)
              int amount = 0;
              for(int x = 0; x <= s.length(); x++)
                   if (s.charAt(x) == value){
                        amount++;
              return amount;

  • HT201774 How do I delete excess email messages from my iPhone.  There are 300 messages listed, and every time I delete some, more are added from old messages.  How do I limit the number of messages that can appear on my phone?  How can I delete messages i

    How do I delete excess email messages from my iPhone.  There are 300 messages listed, and every time I delete some, more are added from old messages.  How do I limit the number of messages that can appear on my phone?  How can I delete messages in bulk,

    You can't.
    All photos transferred from your computer are stored in the Photo Library. The photos in the album or albums below are not duplicates - they include a pointer to the original photos stored in the Photo Library. This way you can view the photos in a particular album only by selecting the album, or you can view all photos available in all albums by selecting Photo Library.
    Just as with an iTunes playlist. A song cannot be in an iTunes playlist unless the song is in the main iTunes library. Placing a song in a playlist does not duplicate the song. Remove the main iTunes library or the songs from the main iTunes library that are in a playlist and the songs will no longer be in the playlist either. This way you can listen to the songs in the playlist only by selecting the playlist, or all songs in your entire iTunes library by selecting Music under Library in the iTunes source list.
    The same with iPhoto on a Mac. A photo cannot be in an in iPhoto Event or Album unless the photo is in the main iPhoto library. Placing a photo in an Event or Album does not duplicate the photo. This way you can view the photos in an iPhoto Event or Album only by selecting the Event or Album, or all photos in all Events or Albums.

  • How to calculate the number of days until your next birthday. Only using current month, day and birth month and day.

    I'm trying to calculate the number of days until your next birthday. Only using current month, day and birth month and day. I can get close but i'm way off. When i enter in the next day, the amount of days is supposed to be 364. This is where I am having problems. I know my code is way off. I just need some guidance please!
    Attachments:
    D5.7_1.vi ‏8 KB

    I just had a little fun with the Time Record...
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    D5.7_1_BD.png ‏19 KB

Maybe you are looking for

  • View Doc (pdf, image, .doc) imported as BLOB files in UIImageView within a UIScrollView.

    Hi, I am new to IOS programming and after researching on topic i found post saying it is possible to view BLOB file in uiimageView. I have already done sucessfully for BLOB file of Image. but i can not view pdf file, even if i got NSData. /****** fro

  • Variance between MB5L and MMBE

    Dear all, My client finds the variance between these two t codes for one specific material.that s why they are not able to pass the balance sheet. Please let me know the possible reasons. Kindly let me know through functional side instead of going th

  • Where firefox backup my bookmarks?

    hi, while I was playing with my linux, I removed some essential libraries and firefox cannot restart anymore. I cannot reinstall the missing libraries, then I will reinstall my distro again. But I want backup my bookmarks, but all info that I found a

  • Error code 8003 when empty trash

    Trying to free up disk space.  Can not empty trash.  error code 8003.  How do I empty trash.

  • Error: iTunes could not copy **** to MyiPod because the iPod disconnected

    I am using Lion 10.7.3 with 10.6.1 and an iPod Touch 2nd generation with iOS 5.1.  It all started because I noticed some of my songs were not properly tagged.  So, I went into iTunes to fix them.  Then, I plugged in the iPod and hit sync.  But, it di