Getting parts of a string (using regexp_instr, REVERSE, ...)

Hi,
I'm trying to alter our company's existing procedure, so that it can extract the Nr of the house, and the bus ('mailbox') from the field "pio_address.street_nr_bus".
Now, if the input is something simple like "Testlane 15 A", there's no problem ofcourse, but since the data comes from what people entered in a form (on our site for example), it can get really messy and the input might be like:
[streetpart1] [streetpart2] [streetpart 3] [NR] [NRpart2] [mailbox] ==> ex: "Test 2 Lane 15 B A"
So in that example, I'd like to get "15 B A" (being a combination of house-nr and mailbox-nr)
So what I've come op with for now (would love to simplify it though) is the following code; but the procedure takes 30 minutes to complete now (~7000 records), which seems rather long, especially since it used to last like 5-10 minutes.
Any ideas/tips?
code:
SELECT REGEXP_REPLACE(trim(REVERSE(pio_address.street_nr_bus)),' *',' ') INTO pio_address.street_nr_bus
FROM DUAL;
SELECT REGEXP_INSTR(pio_address.street_nr_bus, '[[:digit:]]') INTO v_posnr FROM DUAL;
SELECT REGEXP_INSTR(pio_address.street_nr_bus, '[[:alpha:]]', v_posnr) INTO v_posstreet FROM DUAL;
IF v_posstreet = 0 THEN
SELECT REVERSE(pio_address.street_nr_bus) INTO v_nrbus FROM DUAL;
ELSE
SELECT trim(REVERSE(substr(pio_address.street_nr_bus,1, v_posstraat-1))) INTO v_nrbus FROM DUAL;
END IF;
*****UPDATE*****
it appears that this part of the code isn't what's slowing the procedure down, but if someone still knows a "shorter" way to accomplish what I'm doing with this code, tips are always welcome
Edited by: user11236545 on Mar 27, 2012 2:47 AM
Edited by: user11236545 on Mar 27, 2012 2:49 AM

thanks, normally that would have been a great solution!
...buuuut I've just got some more examples of what my input might be, and instead of just 'Test 2 Lane 15 B A'
it could also be something like 'Test 2 Lane 15B BUS 2'
so, since the last character can also be a number ...
this is what I've got atm:
SELECT REVERSE(REGEXP_REPLACE(UPPER(pio_adres),'POSTBUS|BUS',''))
INTO pio_adres FROM DUAL;
SELECT REGEXP_REPLACE(trim(pio_adres),' *',' ') INTO pio_adres
FROM DUAL;
SELECT regexp_instr(pio_adres, '[[:alpha:]]{3,50}')
INTO v_streetpos FROM dual;
Now, like before, when using the old source; running the procedure takes 5minutes;
and running the new source (with this piece of code added), it takes like 35 minutes...
I'm testing it on about 7000 records, so yeah, the procedure suddenly has to do 3 extra selects 7000 times, but 30 minutes extra is waaaay too long. It doesn't seem normal to me, does it?

Similar Messages

  • Javascript - getting part of a string

    I guess this is not a dreamweaver question per se, more
    strictly javascript
    but I know a lot of people here are pretty well versed so I
    hope it is ok
    if I ask here.
    I have the strings
    Method1 ($5.49)
    Method2 ($9.99)
    I wish to retrieve just the numerical values and assign them
    to variables.
    So I guess in pseudocode what I want is to get whatever lies
    between the
    character strings '$' and ')' leaving me with 5.49 and 9.99
    respectively.
    I've been fiddling with str.match and other regular
    expression things which
    I do not fully understand and so far no luck.
    Any help is much appreciated.

    I know about regexp but don't know how to do what I need.
    Anywhere in
    particular you know of that can explain it? I've been stuck
    trying to
    figure it out for quite a while now.
    "Franz Marksteiner" <[email protected]> wrote
    in
    news:f4diu5$7of$[email protected]:
    > "E Eds" <[email protected]> schrieb im Newsbeitrag
    > news:[email protected]..
    >>I guess this is not a dreamweaver question per se,
    more strictly
    >>javascript
    >> but I know a lot of people here are pretty well
    versed so I hope it
    >> is ok if I ask here.
    >>
    >> I have the strings
    >>
    >> Method1 ($5.49)
    >> Method2 ($9.99)
    >>
    >> I wish to retrieve just the numerical values and
    assign them to
    >> variables.
    >>
    >> So I guess in pseudocode what I want is to get
    whatever lies between
    >> the character strings '$' and ')' leaving me with
    5.49 and 9.99
    >> respectively.
    >>
    >> I've been fiddling with str.match and other regular
    expression things
    >> which
    >> I do not fully understand and so far no luck.
    >>
    >> Any help is much appreciated.
    >
    > Try to read into "RegExp" (Regular Expressions).
    > RegExp will allow you to specify some pattern, and
    extract parts (in
    > your case the numerical ones) of it.
    >
    >

  • Using INSTR to extract part of the string ?

    Morning guys and Happy Friday.
    I have a situation where I have to pull out part of the string using a select statement.
    Here is the string and I have to get the contents between the 2nd and 3rd backslash. So, basically, I have to extract marypoppins. Any ideas ?
    C:\USERS\marypoppins\Docs\SpecificationHere is where I started ... and I have stumbled upon trying to find the 3rd backslash. I can easily start the INSTR at 4 because I know that it will always be 'C:\'
    select select substr(C:\USERS\marypoppins\Docs\Specification',
                                INSTRB('C:\USERS\marypoppins\Docs\Specification', '\', 4), .....) from dual;

    Additionally you can break it all up simply with regular expressions..
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'C:\USERS\marypoppins\Docs\Specification' as txt from dual)
      2  -- END OF TEST DATA
      3  select rownum, regexp_substr(txt, '[^\]+',1,rownum) as element
      4  from t
      5* connect by rownum <= length(regexp_replace(txt,'[^\]'))+1
    SQL> /
        ROWNUM ELEMENT
             1 C:
             2 USERS
             3 marypoppins
             4 Docs
             5 Specification
    SQL>

  • How Do I Mirror A Part Of A String?

    Dear Programmers,
    Does Anyone know how to mirror a string in C#:
    For example:  looks -> skool
    Thank you in advance,

    There is a Reverse method:
    string s = "looks";
    s = new string(s.Reverse().ToArray());
    Best way to reverse a string:
    http://stackoverflow.com/questions/228038/best-way-to-reverse-a-string
    And you can get a part of a string using the Substring method:
    https://msdn.microsoft.com/en-us/library/system.string.substring(v=vs.110).aspx
    Please remember to mark helpful posts as answer to close your threads and then start a new thread if you have a new question.

  • Use REGEXP_INSTR to find a text string with space(s) in it

    I am trying to use REGEXP_INSTR to find a text string with space(s) in it.
    (This is in a Function.)
    Let's say ParmIn_Look_For has a value of 'black dog'. I want to see if
    ParmIn_Search_This_String has 'black dog' anywhere in it. But it gives an error
    Syntax error on command line.
    If ParmIn_Look_For is just 'black' or 'dog' it works fine.
    Is there some way to put single quotes/double quotes around ParmIn_Look_For so this will
    look for 'black dog' ??
    Also: If I want to use the option of ignoring white space, is the last parm
    'ix' 'i,x' or what ?
    SELECT
    REGEXP_INSTR(ParmIn_Search_This_String,
    '('||ParmIn_Look_For||')+', 1, 1, 0, 'i')
    INTO Position_Found_In_String
    FROM DUAL;
    Thanks, Wayne

    Maybe something like this ?
    test@ORA10G>
    test@ORA10G> with t as (
      2    select 1 as num, 'this sentence has a black dog in it' as str from dual union all
      3    select 2, 'this sentence does not' from dual union all
      4    select 3, 'yet another dog that is black' from dual union all
      5    select 4, 'yet another black dog' from dual union all
      6    select 5, 'black dogs everywhere...' from dual union all
      7    select 6, 'black dog running after me...' from dual union all
      8    select 7, 'i saw a black dog' from dual)
      9  --
    10  select num, str
    11  from t
    12  where regexp_like(str,'black dog');
           NUM STR
             1 this sentence has a black dog in it
             4 yet another black dog
             5 black dogs everywhere...
             6 black dog running after me...
             7 i saw a black dog
    5 rows selected.
    test@ORA10G>
    test@ORA10G>pratz
    Also, 'x' ignores whitespace characters. Link to doc:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm#i1048942
    Message was edited by:
    pratz

  • Is there a way to get the actual XML string when using the JAXP SAX Parser?

    Hi All,
    I am using a JAXP SAX xml parser and am looking for a way to get the actual line of xml that is being parsed from within a content handler.
    Here's my scenario. Consider the following example xml document.
    <formCollection>
       <form name="myForm">
          <text/>
          <selection/>
       </form>
       <form name="anotherForm">
          <text/>
       </form>
    </formCollection>My hope is to validate the entire document and then insert an xml string containing each "form" element (and its sub-elements) into a map for later use. My thought was to create a String as each "form" element is being parsed (begining with the form's startElement event and concatenating until the form's endElement event is reached) and then inserting this string into the map. Is there a way to get the actual line of xml that is being parsed, rather than just the element name and attribute values?

    DrClap wrote:
    YouRang wrote:
    2. The first handler would validate the entire XML document, extract the "type" attribute from each <form> element, and place each <form> element and its sub-elements into the map of Strings, using the "type" attribute as the key. The second handler would take a <form> element and parse it into a Form object for the display. This option was the impetus for my question because it relies on the first handler being able to access the entire <form> element XML String and write it to a map.I don't see why you need the raw data from the XML document here. You should already be abstracting your data into Java classes in the first handler, instead of making the second handler do the parsing all over again.Correct, I am not referring to XForms. In this case, it happens that I am using the XML to generate an SWT ScrolledForm object and, thus, the XML element name happens to be named "form." However, the concept/design problem could apply to any type of object and the XML element could be appropriately renamed.
    My experience with XSLT is limited and I haven't done anything with it for several years. With that said, it seems that it is primarily used for generating web content, which wouldn't apply in this case because this is for a client-server application. I could be off base on this one -- if XSLT applies to much broader translations and would be more appropriate for generating Java objects than my current methodology, I could certainly look into it further.
    I apologize that option two didn't make more sense; it is difficult to explain. Yes, optimally the data should be abstracted into Java classes in the first handler. This is really an elaboration that I failed to specify when explaining option one. The problem is that the user can choose to create any number of "forms" of any type. For instance, let's say that from the File -> New menu there are options for seven different types of forms and each form is used to send completely different data. The user can select form1, select form1 again, select form4, and select form7 (or any other combination) and bring up tabs that display the different forms. The user can then enter data and submit each form separately. When the user selects File -> New -> FormX, a SWT ScrolledForm object that corresponds with FormX must be given to the display. Because SWT ScrolledForm objects do not allow a deep copy, I cannot simply read the XML <form> elements at initialization, parse them into ScrolledForm objects, and pass deep copies of the ScrolledForm objects to the display each time the user clicks File -> New -> FormX. The only simple way I see of getting a new copy of a ScrolledForm object is to reparse the appropriate XML <form> element in order to create one each time the user selects File -> New -> FormX. As such, one handler would need to read the entire XML document and parse the <form> elements into a map (or some other data structure) and another handler would need to parse individual <form> elements into SWT ScrolledForm objects. The first handler would be called at initialization and the second handler would be called each time a user clicked on File -> New -> FormX. Once again, this isn't exactly my favorite implementation... but seems the simplest given that there is no way to do a deep copy of an SWT ScrolledForm object. Hopefully that makes a little more sense. No worries if it doesn't -- I just figured I'd throw this out there and see if anyone had a better idea.

  • How can i get getwayed url string using pluggable nav in news portlet?

    hi.
    How can i get getwayed url string using pluggable nav in news portlet?
    A code just like below is what I want.
    <param value="param=http://.../portal/server.pt/gateway/PTARGS_.../http/...">
    I tryed the following, but didn't work as I wanted.
    1.<param value="<pcs:valueexpr='var'/>">
    -> transformed. but I want the prefix 'param=' in the enquoted string's too.
    2. <param value="param=<pcs:valueexpr='var'/>">
    -> not transformed.
    Any idea?
    Hiroyuki

    Hi all,
    We have HPROF functionality in our latest roadmap, so you will see that feature in our next major release called JRockit R28.
    I recommend, above from the MemLeak documentation suggested by Makiey, the following information on how to use JRockit tools.
    Performance Tuning & Profiling:
    http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_02.html
    Using JRockit tools:
    http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_03.html
    Diagnostics & Troubleshooting
    http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_04.html
    Best Regards,
    Tuva
    JRockit PM

  • Reverse Strings using rercursion and iteration

    Hi,
    I really need some help, am quite new to java and am struggling.
    I want to design 2 methods, both 2 reverse strings.
    1) uses StringBuffer and iteration
    2) uses Strings and recursion
    I would be greatful for any advice or help.
    Thanx xxxxx Nats xxxxxx

    Oh, you need to do it using both methods.... Sorry, didn't realise it was coursework :)
    Using StringBuffer and iteration
    public StringBuffer reverse(StringBuffer buff) {
        int halfLen = buff.length();
        int len = buff.length();
        for(int i=0; i < halfLen; i++) {
             char c1 = buff.getCharAt(i);
             char c2 = buff.getCharAt((len - i) - 1);
             buff = buff.setCharAt(i, c2);
             buff = buff.setCharAt((len - i) - 1, c1);
        return buff;
    }And for String using recursion
    public String reverse(String str) {
        char[] chars = new char[str.length];
        str.getChars(0, chars, 0, str.length());
        reverseChars(chars, 0, str.length() / 2);
        return new String(chars);  
    private reverseChars(char[] chars, int index, int halfLen) {
        //* end condition
        if(index >= halfLen) return;
        topIndex = (chars.length - 1) - index;
        char tmp = chars[index];
        chars[index] = chars[topIndex];
        chars[topIndex] = tmp;
        reverseChars(chars, ++index, halfLen);
    }I only wrote this code on the fly so things may break but it is a start.

  • How to separate part of string using separator in java

    Hi
    I want to separate a part of a string having separator (/)
    FirstName / MiddleName / LastName
    Please help me

    MayureshJoshi wrote:
    Hi
    I want to separate a part of a string having separator (/)
    FirstName / MiddleName / LastName
    Please help meString.split(...)

  • Get part of string

    I have the following string:
    jdbc:odbc:dbName
    I wish to get "dbName" from the string?

    I have the following string:
    jdbc:odbc:dbName
    I wish to get "dbName" from the string?Parse it. :)
    If the string always is constructed as follows:
    <string>:<string>:<string>
    Then you can just split it with regular expressions or with the stringtokenizer:
      String dbName = "jdbc:odbc:dbName".split(":")[2];

  • How to get the hour:minuts:seconds using java

    I have table xydata
    here i get the gsTime like this 2010-04-21 10:58:40
    the above time i want to get only 10:58:40
    how to write the java for this
    please help me
    Thanks in Advance

    Problem of this sort cry out for using regular expressions. It is what they were invented for. If the OP wanted the whole date parsed into a java.util.Date then it would be a different matter and SimpleDateFormat would be the way to go but extracting part of a string is what regular expressions are best at.
    In this case, even a regular expression approach is far too complex. Which of the following do you consider the most appropriate ?
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Sabre20100508
        public static void main(String[] args) throws Exception
            String[] lines =
                "2010-04-21 11:01:35",
                "2010-04-21 11:01:58",
                "2010-04-21 11:02:21",
                "2010-04-21 11:02:42",
                "2010-04-21 11:03:28",
                "2010-04-21 11:03:51"
                Pattern p = Pattern.compile("(?<= )\\d{2}:\\d{2}:\\d{2}");
                System.out.println("Method 1 :-");
                for (String line : lines)
                    Matcher m = p.matcher(line);
                    if (m.find())
                        System.out.printf("    [%s]\n", m.group());
                Pattern p = Pattern.compile("\\d{4}-\\d{2}-\\d{2} (\\d{2}:\\d{2}:\\d{2})");
                System.out.println("Method 2 :-");
                for (String line : lines)
                    Matcher m = p.matcher(line);
                    if (m.matches())
                        System.out.printf("    [%s]\n", m.group(1));
                System.out.println("Method 3 :-");
                for (String line : lines)
                    String[] splitLIne = line.split(" ", 2);
                    System.out.printf("    [%s]\n", splitLIne[1]);
                System.out.println("Method 4 :-");
                for (String line : lines)
                    int index = line.lastIndexOf(" ");
                    System.out.printf("    [%s]\n", line.substring(index + 1));
                System.out.println("Method 5 :-");
                SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
                for (String line : lines)
                    Date date = parser.parse(line);
                    System.out.printf("    [%s]\n", formatter.format(date));
                System.out.println("Method 6 :-");
                for (String line : lines)
                    System.out.printf("    [%s]\n", line.replaceAll("[^ ]* ", ""));
    }My vote goes to method 4!

  • Converting part of the string to a date and subtract with sysdate.

    HINT! In order solve this you must know how the pnr is assembled. Study this:
    650323-5510, we only need the first six characters. They inform us about when the person (car owner) was born. In this case it is 23 Mars 1965. You have to use several oracle built-in-functions to solve this. Hint! Begin by converting part of the string to a date and subtract with sysdate.
    select to_char(to_date(cast(pnr,'YYMMDDMM'))) from car_owner;
    please what am i doing wrong. i need the result to be something like this
    Hans, Rosenboll, 59,6 years.

    Hi.
    The main problem here is you have only last two digits of year. That could be the problem in a couple of years from now, when somebody born after 2k would get in to your database. For now if we ignore this problem the right solution would be :
    <code>
    SELECT months_between(trunc(SYSDATE),
    to_date('19' || substr('650323-5510',
    1,
    6),
    'YYYYMMDD')) / 12 years_old
    FROM dual
    </code>
    Suppose you are expecting the age of the car owner as a result above code will give you that. One again notice the '19' I appended.
    Best regards.

  • Delete part of a string question

    Hello I have this String 12a
    I need to get a the value 12 of it an make it an int
    But the problem is that I don't know what the string is it can be
    12
    or 12 a
    or 12a
    It is for people to fill in there house address and this is the number part.
    The string is like this String number ="\"12a\"";
    Is it possible to look for a letter in a String and delete it if you only want ints???

    Try this on the command line. Dealing with java.lang.NumberFormatException in cases where the number is too large is left as an exercise.
    Harald.
    import java.util.regex.*;
    * demonstrates use of <code>java.util.regex</code> to check if a
    * string starts with digits.
    public class bla {
       * thrown by {@link #getNumber} if the given string does not start
       * with digits.
      private static class BoomBoom extends Exception {
        public BoomBoom(String msg) {super(msg);}
       * reusable pattern to check for digits.
      private static Pattern p = Pattern.compile("[0-9]+");
       * convert leading digits of the parameter to an <code>int</code>
       * and return it.
       * @throws BoomBoom if the parameter does not start with digits.
      public static int getNumber(String s) throws BoomBoom {
        Matcher m = p.matcher(s);
        if( !m.lookingAt() ) {
          throw new BoomBoom("The string `"+s+"' does not start with "
                    +"a positive number.");
        return Integer.parseInt(m.group(0));
      // don't clutter the javadoc
      private bla() {}
       * passes each command line argument through {@link #getNumber} and
       * prints the output or error to <code>System.out</code> or
       * <code>System.err</code> respectively.
      public static void main(String[] argv) {
        for(int i=0; i<argv.length; i++) {
          try {
         System.out.println("Your string `"+argv[i]
                      +"' starts with number "
                      +getNumber(argv));
    } catch( BoomBoom e ) {
         System.err.println(e.getMessage());

  • How to get the Mobile information by using J2ME application

    hi all,
    I am lakshman.I am developing an application in j2me,I want my program compatible to all mobile devices.
    I want to know properties and the device information with the help of a j2me application.I got the information with the help of System.getProperty(String).I found some of the information like sms,videocapture,and some of the values and the variables ... in the following
    platform...null
    encoding...ISO-8859-1
    configuration...CLDC-1.0
    profile...MIDP-2.0
    locale...null
    fileconnection...1.0
    comport...null
    hostname...iwmc-07
    sms...null
    smartcard...null
    location version...null
    sip version...null
    m3gversion...null
    mms...null
    videocapture...false
    videoencoding...null
    snapshotencoding...encoding=png encoding=jpeg encoding=gif encoding=bmp
    audioencoding...null
    supaudcap...false
    suprecod...false
    supmixing...false
    mediaversion...1.1
    streamcont...null
    I want to know these are the only variables or is there are lot...
    Now my question is I want to get the information of the service provider and also the present location that the mobile was present.I think there was some method to get that ...I want to get what firmware it was using .
    Can anybody tell me that way and also the package to get the information
    thanks in advance
    lakshman

    hi all,
    I am lakshman,I found the answer for my question,By using the Location API(jsr179).It was not include in the WTK2.2.for that i have downloaded the WTK2.3 then i have implemented the location api in the application and it was working.
    And I have the following warning...
    Warning: To avoid potential deadlock, operations that may block, such as
    networking, should be performed in a different thread than the
    commandAction() handler.
    I am running the application from my Emulator(by using the default color phone).I have to check that in the device.
    Can any body please give me the way to fix that,i want to test my application from my emulator is that is possible if possible ...how?.what is the procedure to implement..
    thanks in advance

  • Multi-language support for user-specified text strings used in the forms

    multi-language support for user-specified text strings used in the forms
    Instead of creating multiple forms, 1 in each different language, for the same service, is there any workaround?

    Hoan - is your question what are the considerations when creating multiligual catalogs? If so, I can tell you that at other clients I have seen them use a single catalog for one or two languages. For the two langugages, such as Spanish/English, you can create a single catalog with both of them. Once you get to more than two languages, the catalog would get unweildy and is therefore not suggested.

Maybe you are looking for

  • How can i transfer more than one file from server to client

    Hi, our requirement is transfer more than one files from server to client using the webutil_file_transfer.as_to_client_with_progress.One file transfer is already working in our system.If anybody know the solution please inform regards mat

  • Mac noob needs monitor help! how do I...

    I was given a 2003 imac as a gift. I've always had PCs but was thrilled to have my first mac to play around with. The bad news is that about half the time the monitor doesn't work!!! I turn the computer on and the screen comes on for a split second a

  • 10.6.8 Server - workgroup manager not authenticated

    I have 10.6.8 Server that has suddenly stopped accepting the dradmin password when using Workgroup Manager.  Workgroup Manager connects, but in not authenticated mode.  When I click the lock icon and am prompted for the ID & Password it is rejected. 

  • Deserialization failure when using JWS

    Hi folks, I have an application which works fine without being launched from JWS, but when I tried to use JWS to open it, it somehow failed a critical deserialization procedure in my program. This happens inside a thread: public void run(){ XMLDecode

  • Move cloud licence to another computer for one week

    I've come away from the office with my laptop but forgotten the charger so I can't use Creative cloud on it. Is there any way I could run it from my home desktop for one week only?