Count the no. of dots in a string

Hi Friends
I have a column named Hiercode in table A which has a column hier_code with data like 1234.56.56.3
I need to insert this data into table B in different columns
Like
Level1 Level 2 Level3 Level 4 ........ Max_level
1234 56 56 3 4
We don't know in advance how many periods the hier_code data has
Could you please suggest me or gimme a small piece of code of how to do it in PL/SQL...I would really appreciate it and it has to be submitted today...So it will help me a lot...
Thankyou
Mohit

This isn't elegant, but maybe its what you are looking for?
create table dottab (hier_code varchar2(200));
insert into dottab values ( '101') ;
insert into dottab values ( '101.102') ;
insert into dottab values ( '101.102.103') ;
insert into dottab values ( '101.102.103.104') ;
insert into dottab values ( '101.102.103.104.105') ;
insert into dottab values ( '101.102.103.104.105.106') ;
insert into dottab values ( '101.102.103.104.105.106.107');
insert into dottab values ( '101.102.103.104.105.106.107.108');
insert into dottab values ( '101.102.103.104.105.106.107.108.109');
insert into dottab values ( '101.102.103.104.105.106.107.108.109.110');
commit;
column level1 format a6;
column level2 format a6;
column level3 format a6;
column level4 format a6;
column level5 format a6;
column level6 format a6;
column level7 format a6;
column level8 format a6;
column level9 format a6;
column level10 format a7;
SELECT substr(hier_code,1,decode(instr(hier_code,'.',1,1),0,length(hier_code),instr(hier_code,'.',1,1)-1)) level1,
       decode(instr(hier_code,'.',1,1),0,NULL,substr(hier_code,instr(hier_code,'.',1,1)+1,
           decode(instr(hier_code,'.',1,2),0,length(hier_code),instr(hier_code,'.',1,2)-instr(hier_code,'.',1,1)-1))) level2,
       decode(instr(hier_code,'.',1,2),0,NULL,substr(hier_code,instr(hier_code,'.',1,2)+1,
           decode(instr(hier_code,'.',1,3),0,length(hier_code),instr(hier_code,'.',1,3)-instr(hier_code,'.',1,2)-1))) level3,
       decode(instr(hier_code,'.',1,3),0,NULL,substr(hier_code,instr(hier_code,'.',1,3)+1,
           decode(instr(hier_code,'.',1,4),0,length(hier_code),instr(hier_code,'.',1,4)-instr(hier_code,'.',1,3)-1))) level4,
       decode(instr(hier_code,'.',1,4),0,NULL,substr(hier_code,instr(hier_code,'.',1,4)+1,
           decode(instr(hier_code,'.',1,5),0,length(hier_code),instr(hier_code,'.',1,5)-instr(hier_code,'.',1,4)-1))) level5,
       decode(instr(hier_code,'.',1,5),0,NULL,substr(hier_code,instr(hier_code,'.',1,5)+1,
           decode(instr(hier_code,'.',1,6),0,length(hier_code),instr(hier_code,'.',1,6)-instr(hier_code,'.',1,5)-1))) level6,
       decode(instr(hier_code,'.',1,6),0,NULL,substr(hier_code,instr(hier_code,'.',1,6)+1,
           decode(instr(hier_code,'.',1,7),0,length(hier_code),instr(hier_code,'.',1,7)-instr(hier_code,'.',1,6)-1))) level7,
       decode(instr(hier_code,'.',1,7),0,NULL,substr(hier_code,instr(hier_code,'.',1,7)+1,
           decode(instr(hier_code,'.',1,8),0,length(hier_code),instr(hier_code,'.',1,8)-instr(hier_code,'.',1,7)-1))) level8,
       decode(instr(hier_code,'.',1,8),0,NULL,substr(hier_code,instr(hier_code,'.',1,8)+1,
           decode(instr(hier_code,'.',1,9),0,length(hier_code),instr(hier_code,'.',1,9)-instr(hier_code,'.',1,8)-1))) level9,
       decode(instr(hier_code,'.',1,9),0,NULL,substr(hier_code,instr(hier_code,'.',1,9)+1,length(hier_code))) level10
FROM   dottab;
LEVEL1 LEVEL2 LEVEL3 LEVEL4 LEVEL5 LEVEL6 LEVEL7 LEVEL8 LEVEL9 LEVEL10
101
101    102
101    102    103
101    102    103    104
101    102    103    104    105
101    102    103    104    105    106
101    102    103    104    105    106    107
101    102    103    104    105    106    107    108
101    102    103    104    105    106    107    108    109
101    102    103    104    105    106    107    108    109    110Obviously, you will need to turn this into an insert statement from just a select.
Greg Pike
http://www.singlequery.com

Similar Messages

  • Count the number of occurrence in a string

    is there any api for counting the number of occurrence in a string or should i write a method myself?
    for example. I want to count "." in "1.2.3.4.". i want to count the dot in this string.
    I am just wondering.
    Thanks in advance.

    is there any api for counting the number of
    occurrence in a string or should i write a method
    myself?The latter.

  • How i can count the number of words in a string?

    hi, i want to know how to count the number of words in a string
    e.g. java is a very powerful computer language.
    i will get 7 words.
    thanks in advance..

    Jverd, this has actually been answered, but due to an
    attack of goldie-itis, all the answers were hosed.
    The OP did get an answer, though.Yeah, I know. I just didn't know if he saw the answer before it went away.

  • Which method to count the number of character in a string?

    Hi all,
    I want to know which class and method to count the number of character in a string?
    Gary

    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

  • How count the number of substrings in a string

    Hi all,
    I wonder if someone can help me and point out where I'm going wrong.
    I want to count the number of substring starting with 'd' and ending with 'e' in a string supplied by a user.
    currently my code is only counting the number of 'd' and 'e' characters in the string.
        public static void main (String [] args)
             Scanner input = new Scanner (System.in);
             String mstring;// string variable that the user will enter
             int i = 0; // upstep variable
             int count = 0; // int variable to count the number of substrings
             System.out.print("Enter a string: ");
             mstring = input.nextLine();
             while (i != mstring.length())
                       if(mstring.charAt(i)=='d'){count++;}
                       else if (mstring.charAt(i)=='e'){count++;}
                       i++;
             System.out.println("The total d e substrings is " + count);
    }For example if the user enters adbedeaadffe the total number of substrings should be 5 but I'm getting 6 as the program is just counting the number of times it comes across 'd' and 'e'
    Can anyone shed some light on this for me thanks.

    Hi all I had a good few replies to this question but they seem to have been removed from the system for some reason.
    I've changed my code slightly and it works but only for one round of the guard.
                   Scanner input = new Scanner (System.in)
             String mstring;// main string variable that the user will enter
             int i = 0;  // upstep variable
             int count = 0; // int variable to count the number of substrings
         System.out.print("Enter a string: ");
             mstring = input.nextLine();
             int y =mstring.length();
             while (i != mstring.length() && y !=0)
             if (mstring.charAt(i) == 'd' && mstring.charAt(y-1)=='e'){count = count+1;}
             y--;
             i++;
             System.out.println("The total a b substrings is " + (count));The above code will only print out one substring of adbedeaadffe but that is not what I need, I need to be able to print out all of the substrings.
    Can anyone tell me where I'm going wrong.
    Thanks in advance

  • How do I count the number of *'s in a string?

    I need to count the number of * in a string of carakters. And the return the number. 0 for no *'s in the string 2 for two *'s in the string and so on.
    It's probably quite simple but I can't figure out how!

    Like this.
    james_t_dk wrote in message
    news:[email protected]..
    > I need to count the number of * in a string of carakters. And the
    > return the number. 0 for no *'s in the string 2 for two *'s in the
    > string and so on.
    >
    > It's probably quite simple but I can't figure out how!
    [Attachment Untitled 10.vi, see below]
    Attachments:
    Untitled_10.vi ‏18 KB

  • How do I count the number of occurrences of a string within a group of cells?

    Hello all, I'm trying to figure out how to count the number of times a child has completed certain tasks.  Here is a sample of the data (it is highly simplified here, but contains what I hope is needed to answer my question):
    Unnamed Table
    Objective
    John
    Ann
    Alex
    Dave
    Eric
    20a 20b 20c
    x
    20a 20b 20c
    x
    20a 20b 20c
    x
    x
    19b 20a
          x
           x
    20c 21b 22
         x
    What I am trying to do is count the number of times each child completed each objective - but I can't figure out how to go about splicing up the "objectives" fields for counting while still being able to compare them to whether or not the "child" has 'an x in the box' in that particular row.

    If I read your example correctly, John's counts should be 2 for 20a, 1 for 19b, 20b and 20c, and 0 for any other objectives listed.
    Here's an example that will work for your data set, assuming that any objective ma occur only once in each row of column A of the Main table. I've added an a to objective 22, but I think it is unnecessary, provided there is no objective 122, 221, etc.
    This uses a two step process.
    The table AUX extracts the objectives completed by each student, using the checkboxes in Main. Note that it also adds a space at the beginning and end of each string. This provides an extra character before the first objective code and after the last objective code in that row, used by the wildcard specification in the formula in the Summary table.
    Formula:
    Aux::B2: =IF(OFFSET(Data :: $A$1,ROW()-1,COLUMN()-1)," "&OFFSET(Data :: $A$1,ROW()-1,0)&" ","")
    Fill right to the last column and down to the last row of Aux.
    Summary uses COUNTIF to count the number of occurrences of each of the objectives listed in column A of that table.
    Formula:
    Summary::B2: =COUNTIF(Aux :: B,"=*"&$A2&"*")
    Fill right and down as the previous formula.
    Regards,
    Barry

  • A quick way to count the number of  newlines '/n' in string of 200 chars

    I am trying to establish the number of lines that a string will generate.
    I can do this by counting the number of '/n' in the string. However my brute force method (shown below) is very slow.
    Normally this would not be a problem on a 2800mhz Athlon (Standard) PC this takes < 1 second. However this code resides within a speed critical loop (not shown). The code shown below is a Achilles heal as far as the performance of this speed critical loop goes.
    Can anyone suggest a faster way to count the number of �/n� (new lines) within a text string of around 50- 1000 chars, given that there may be 10 � 100 newline chars. Speed is a very important factor for this part of my program.
    Thanks in advance
    Andrew.
        int lineCount =0;
        String txt = this.getText();
        //loop throught text and count the carridge returns
        for (int i = 0; i < txt.length(); i++)
          char ch = txt.charAt(i);
          if (ch == '\n')
           lineCount ++;
        }//end forMessage was edited by:
    scottie_uk
    Message was edited by:
    scottie_uk

    Well, here is a C version. On my computer the Java version (reply 9 above) is slightly faster than C. YMMV. For stuff like this a compiler can be hard to beat even with assembler, as you need to do manual loop unrolling and method inlining which turn assembly into a maintenance nightmare.
    // gcc -O6 -fomit-frame-pointer -funroll-loops -finline -o newlines.exe newlines.c
    #include <stdio.h>
    #include <string.h>
    #if defined(__GNUC__) || defined(__unix__)
    #include <time.h>
    #include <sys/time.h>
    #else
    #include <windows.h>
    #endif
    #if defined(__GNUC__) || defined(__unix__)
    typedef struct timeval TIMESTAMP;
    void currentTime(struct timeval *time)
        gettimeofday(time, NULL);
    int milliseconds(struct timeval *start, struct timeval *end)
        int usec = (end->tv_sec - start->tv_sec) * 1000000 +
         end->tv_usec - start->tv_usec;
        return (usec + 500) / 1000;
    #else
    typedef FILETIME TIMESTAMP;
    void currentTime(FILETIME *time)
        GetSystemTimeAsFileTime(time);
    int milliseconds(FILETIME *start, FILETIME *end)
        int usec = (end->dwHighDateTime - start->dwHighDateTime) * 1000000L +
         end->dwLowDateTime - start->dwLowDateTime;
        return (usec + 500) / 1000;
    #endif
    static int count(register char *txt)
        register int count = 0;
        register int c;
        while (c = *txt++)
         if (c == '\n')
             count++;
        return count;
    static void doit(char *str)
        TIMESTAMP start, end;
        long time;
        register int n;
        int total = 0;
        currentTime(&start);
        for (n = 0; n < 1000000; n++)
         total += count(str);
        currentTime(&end);
        time = milliseconds(&start, &end);
        total *= 4;
        printf("time %ld, total %d\n", time, total);
        fflush(stdout);
    int main(int argc, char **argv)
        char buf[1024];
        int n;
        for (n = 0; n < 256 / 4; n++)
         strcat(buf, "abc\n");
        for (n = 0; n < 5; n++)
         doit(buf);
    }

  • Count the number of char in a string

    hi gurs
    for example ,there is a string "abcdaa", i want a sql that shows the number of 'a' in the string ,in this case,the sql should return 3 cause there are three 'a' in the string, how to write this sql
    thank you very much.

    As an alternative or if you're using 9i or below you can use this:
    SQL> with t as (
      2  select 'abcdaa' x from dual union all
      3  select 'AbcdaA' x from dual)
      4  -- end of sample data
      5  SELECT x, length(x) - length(replace(x, 'a', '')) count_chr
      6    FROM t;
    X       COUNT_CHR
    abcdaa          3
    AbcdaA          1
    SQL>

  • 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);

  • 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.

  • I need to WAP to count the number of occurences of an alphabet in a string.

    I need to WAP to count the number of occurences of an alphabet in a string.I tried a lot and have surfed a lot regarding this problem.
    I m not the most proficient with java.but this is all i could come up with,and would appreciate some help here.I hope you guys would help me find a solution to this.
    e.g String : abcabrty
    Result should be
    a:2
    b:2
    c:1
    r:1
    t:1
    y:1
    public class chkoccurences
         public static void main(String args[ ])
              String user_Data=args[0];
              int counter=0;     
              try
                   for(int i=0;i<user_Data.length( );i++)
                        for(int j=0;j<user_Data.length( );j++)
                             if(user_Data.charAt(i) == user_Data.charAt(j))
                             counter++;
                        System.out.println(user_Data.charAt(i)+" exists "+counter+" time(s) in the word.");
                   System.out.println(" ");
              catch(ArrayIndexOutOfBoundsException e)
                   System.out.println("Check the array size.");
    }This is the output i get out of the program:
    a exists 2 time(s) in the word.
    b exists 4 time(s) in the word.
    c exists 5 time(s) in the word.
    a exists 7 time(s) in the word.
    b exists 9 time(s) in the word.
    r exists 10 time(s) in the word.
    t exists 11 time(s) in the word.
    y exists 12 time(s) in the word.What i think is i need an array to store the repeated characters because the repeated characters are getting counted again in the loop,if you know what i mean.
    Please, i would appreciate some help here.

    Criticism is welcomed
    public class tests {
         final int min = 10;
         final int max = 35;
         final char[] chars = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
                   'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
                   'v', 'w', 'x', 'y', 'z'};
         public static void main(String[] args){
              tests t = new tests();
              String[] strings = new String[] {"aabcze", "att3%a", ""};
              for(String s : strings){
                   System.out.println(t.getAlphaCount(s));
         public String getAlphaCount(String s){
              int[] alphaCount = new int[26];
              int val;
              for(char c : s.toCharArray()){
                   val = Character.getNumericValue(c);
                   if( (val>=min) && (val<=max)){
                        alphaCount[val-min]++;
              StringBuilder result = new StringBuilder();
              for(int i=0; i<alphaCount.length; i++){
                   if(alphaCount[i] > 0){
                        result.append(chars[i] + ":" + alphaCount[i] + ", ");
              if(result.length() != 0){
                   result.delete(result.length()-2, result.length());
              return result.toString();
    }

  • Fastest way to count the number of occurences of string in file

    I have an application that will process a number of records in a plain text file, and the processing takes a long time. Therefore, I'd like to first calculate the number of records in the file so that I can display a progress dialog to the user (e.g. " 1234 out of 5678 records processed"). The records are separated by the string "//" followed by a newline, so all I need to do to get the number of records is to count the number of times that '//' occurs in the file. What's the quickest way to do this? On a test file of ~1.5 Gb with ~500 000 records, grep manages under 5 seconds, whereas a naive Java approach:
    BufferedReader bout = new BufferedReader (new FileReader (sourcefile));
                   String ffline = null;
                   int lcnt = 0;
                   int searchCount = 0;
                   while ((ffline = bout.readLine()) != null) {
                        lcnt++;
                        for(int searchIndex=0;searchIndex<ffline.length();) {
                             int index=ffline.indexOf(searchFor,searchIndex);
                             if(index!=-1) {
                                  //System.out.println("Line number " + lcnt);
                                  searchCount++;
                                  searchIndex+=index+searchLength;
                             } else {
                                  break;
                   }takes about 10 times as long:
    martin@martin-laptop:~$ time grep -c '//' Desktop/moresequences.gb
    544064
    real     0m4.449s
    user     0m3.880s
    sys     0m0.544s
    martin@martin-laptop:~$ time java WordCounter Desktop/moresequences.gb
    SearchCount = 544064
    real     0m42.719s
    user     0m40.843s
    sys     0m1.232sI suspect that dealing with the file as a whole, rather than line-by-line, might be quicker, based on previous experience with Perl.

    Reading lines is very slow. If your file has single byte character encoding then use something like the KMP algorithm on an BufferedInputStream to find the byte sequence of "//\n".getBytes(). If the file has a multi-byte encoding then use the KMP algorithm on a BufferedReader to find the chars "//\n".getCharacters() .
    The basis for this can be found in reply #12 of http://forum.java.sun.com/thread.jspa?threadID=769325&messageID=4386201 .
    Edited by: sabre150 on May 2, 2008 2:10 PM

  • 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.

  • 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

Maybe you are looking for

  • How do I add a guest network to existing airport extreme configuration?

    I have an existing Airport Extreme configuation in my home Wifi network and I want to add a guest access point.  When I open the recently updated airport utilities, the screen no longer looks the way it used to, with the side bar on the left and my d

  • Regarding goods receipt for  scheduling aagreement-LPA

    Hi All At the time of GR -  refering to scheduling agreement(LPA)  its showing the open order qty zero - if i changed maually(qty is the same as the todays GR qty) and i did check -error msg telling that qty exceeded the order qty. Plz help me to pro

  • How to confiure sendmail in sloaris 10

    pls explain me how to setup sendmail .in my concern we 30 windows work station one solaris 10 x86 server i want to configure sendmail

  • Display Xml forms

    Hi. I have next problem: In my application, user can create xml documents by xml forms. This generated xml files are stored in the KM. My application has another page in order to view/manage these documents. Clicking on the Context Menu, it appears a

  • E-Mail Home!

    Hi! In this code to send e-mail from my app ... can I have the e-mail message be from a "log.txt" file on my computer? This code now reads text for the body of the e-mail from "This is the text sent in the E-Mail Message!" package AddRFSwitchPac; imp