Without using a regular expressions in oracle 9i

dear all;
I have the following test data below
  insert into p
      (id)
    values
      ('\G1\G2'); 
  insert into p
      (id)
    values
      ('\A1\');
   insert into p
      (id)
    values
      ('\B1\B2\B3');
       insert into p
      (id)
    values
      ('\J1\J2\J3\J4');and this is the output I desire though
ID
G1
null
B2
J3the output is gotten by looking at the second to the last entry and extracting it....
so for \G1\G2 the second to the last entry was G1 hence we have G1
for \A1\ there is no second to the last entry and that is why it is null
for \B1\B2\B3 the second to the last entry was B2

Hi,
user13328581 wrote:
... the output is gotten by looking at the second to the last entry and extracting it....
so for \G1\G2 the second to the last entry was G1 hence we have G1
for \A1\ there is no second to the last entry and that is why it is nullSo backslashes at the end of id don't matter. Whether id is
'\AI',
'\A1\' or
'\A1\\\\\\\\\\\\'
there's only entry in id, and so you want to return NULL. Is that right?
Here's one way to do that in Oracle 9:
WITH    got_pos          AS
     SELECT     id
     ,     INSTR ( RTRIM (id, '\')
                , -1
                , 2) + 1     AS pos_from
     ,     INSTR ( RTRIM (id, '\')
                , -1
                , 1)     AS pos_to
     FROM     p
SELECT       id
,       CASE
           WHEN  pos_from     > 1
           THEN  SUBSTR ( id
                            , pos_from
                  , pos_to - pos_from
       END     AS penult
FROM       got_pos
ORDER BY  id
;

Similar Messages

  • Regular expressions in oracle 10 g

    how to use regular expressions in oracle 10g forms

    May be forms related question better answered in forms forum.
    Forms

  • Regular expression vs oracle text performance

    Does anyone have experience with comparig performance of regular expression vs oracle text?
    We need to implement a text search on a large volume table, 100K-500K rows.
    The select stmt will select from a VL, a view joining 2 tables, B and _TL.
    We need to search 2 text columns from this _VL view.
    Using regex seems less complex, but the deciding factor is of course performace.
    Would oracle text search perform better than regular expression in general?
    Thanks,
    Margaret

    Hi Dominc,
    Thanks, we'll try both...
    Would you be able to validate our code to create the multi-table index:
    CREATE OR REPLACE PACKAGE requirements_util AS
    PROCEDURE concat_columns(i_rowid IN ROWID, io_text IN OUT NOCOPY VARCHAR2);
    END requirements_util;
    CREATE OR REPLACE PACKAGE BODY requirements_util AS
    PROCEDURE concat_columns(i_rowid IN ROWID, io_text IN OUT NOCOPY VARCHAR2)
    AS
    tl_req pjt_requirements_tl%ROWTYPE;
    b_req pjt_requirements_b%ROWTYPE;
    CURSOR cur_req_name (i_rqmt_id IN pjt_requirements_tl.rqmt_id%TYPE) IS
    SELECT rqmt_name FROM pjt_requirements_tl
    WHERE rqmt_id = i_rqmt_id;
    PROCEDURE add_piece(i_add_str IN VARCHAR2) IS
    lx_too_big EXCEPTION;
    PRAGMA EXCEPTION_INIT(lx_too_big, -6502);
    BEGIN
    io_text := io_text||' '||i_add_str;
    EXCEPTION WHEN lx_too_big THEN NULL; -- silently don't add the string.
    END add_piece;
    BEGIN
         BEGIN
              SELECT * INTO b_req FROM pjt_requirements_b WHERE ROWID = i_rowid;
              EXCEPTION
              WHEN NO DATA_FOUND THEN
              RETURN;
         END;
         add_piece(b_req.req_code);
         FOR tl_req IN cur_req_name(b_req.rqmt_id) LOOP
         add_piece(tl_req.rqmt_name);
    END concat_columns;
    END requirements_util;
    EXEC ctx_ddl.drop_section_group('rqmt_sectioner');
    EXEC ctx_ddl.drop_preference('rqmt_user_ds');
    BEGIN
    ctx_ddl.create_preference('rqmt_user_ds', 'USER_DATASTORE');
    ctx_ddl.set_attribute('rqmt_user_ds', 'procedure', sys_context('userenv','current_schema')||'.'||'requirements_util.concat_columns');
    ctx_ddl.set_attribute('rqmt_user_ds', 'output_type', 'VARCHAR2');
    END;
    CREATE INDEX rqmt_cidx ON pjt_requirements_b(req_code)
    INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS ('DATASTORE rqmt_user_ds
    SYNC (ON COMMIT)');

  • Regular Expressions in Oracle

    Hello All,
    I come from Perl scripting language background. Perl's regular expressions are rock solid, robust and very fast.
    Now I am planning to master Regular Expressions in Oracle.
    Could someone please point the correct place to start with it like official Oracle documentation on Regular Expressions, any good book on Regex or may be any online link etc.
    Cheers,
    Parag
    Edited by: Parag Kalra on Dec 19, 2009 11:03 AM

    Hi, Parag,
    Look under [R in the index of the SQL language manual|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/index.htm#R]. All the regular expression functions and operators start with "REGEXP", and there are a couple of entries under "regular expressions".
    That applies to the Oracle 11 and 10.2 documentation. Regular expressions were hidden in the Oracle 10.1 SQL Language manual; you had to look up some similar function (like REGR_SYY, itself hidden under S for "SQL Functions", and then step through the pages one at a time.
    Sorry, I don't know a good tutorial or introduction.
    If you find something hopeful, please post a reference here. I think a lot of people would be interrested.

  • Track the entered answer using the Regular expression

    Hi,
    I am building a Q&A application which does have user to answer descriptive answer for the question(Text based answer rather than objective)
    in this case how we can track the entered answer by the user is the correct one? how we can capture the entered answer and then check with the correct
    answer in the DB? Yes we need to use a regular expression , but how we know that entered one is matching with the one in the DB
    as the user can answer in lengthy or short form ? Hence please clarify how we can proceed?
    Thanks.

    797836 wrote:
    Hi,
    I am building a Q&A application which does have user to answer descriptive answer for the question(Text based answer rather than objective)
    in this case how we can track the entered answer by the user is the correct one? how we can capture the entered answer and then check with the correct
    answer in the DB? Yes we need to use a regular expression , but how we know that entered one is matching with the one in the DB
    as the user can answer in lengthy or short form ? Hence please clarify how we can proceed?
    I don't see how regular expressions help at all with this problem ! What made you think they can help?

  • Use a regular expression to do this...

    I need to process this line : "STRTsomeEND.STRTsome2END.STRTsome3END"
    to get an array with this values :
    String[] processedLine = {
    {"STRTsomeEND."}
    {"STRTsome2END."}
    {"STRTsome3END."}
    I tried to use this regular expression to do the work: (STRT[.*]END.)+ but doesn't work. Also I tried with this expresion STRT[.*]END. But I only got the first ocurrence ("STRTsomeEND") .
    Can anybody help me?

    zkropotkine wrote:
    1) "." is a regex flag.I saw in the table and it said that the "." symbol doesn't need the escape: )
    when you ask a question and then someone gives you advice you should
    give them the benefit of the doubt (for at least a little while).
    did you take a moment to try to understand what i was saying about escaping the "."?
    anyway, your regex should be:
    (START)(.*?)(END)\ \ .
    the "?" after the "\*" means "reluctant". you dont want the ".\*" to grab up everything.
    with the reluctant modifier "?" the regex should stop and grab the first available "END".
    and finally, if you meant the "." at the end of "STARTsomethingEND." literally then:
    you need to escape the "."

  • Regular expression in oracle for hypen

    Hi,
    I want to match a word "{color:#993300}83-ASG{color}" using regexp_like and i used '{color:#993300}^83-*{color}' pattern to match this word but this also matches words like "{color:#993300}8307-YUF{color}". could anyone please tell me what pattern should i use to match words like {color:#993300}83-ASG{color}.
    Also i need to know the similar pattern in oracle for the "{color:#993300}\b{}{color}" used in .net.
    Thanks in advance.
    Prasad

    Hi Prasad,
    Your regex could be as simple as '^83-'
    So, not much use for a regular expression:
    SQL> with test_data as (select '83-ASG' txt from dual union all
                       select '8307-YUF' from dual)
    -- end of test data
    select txt from test_data
    where txt like '83-%'
    TXT    
    83-ASG 
    1 row selected.Unless, you add some more value to it, perhaps like
    SQL> with test_data as (select '83-ASG' txt from dual union all
                       select '8307-YUF' from dual)
    -- end of test data
    select txt from test_data
    where regexp_like(txt, '^83-[[:upper:]]{3}$')
    TXT    
    83-ASG 
    1 row selected.Regards
    Peter

  • IR filter using "matches regular expression"

    Hi,
    I am familiar with Perl regular expressions, but I'm having trouble using the IR filter by regular expression in Apex.
    For instance, I would like to search for dates of format 'MM/DD/YY' - can someone tell me how this would be done? I tried '[0-9](2)/[0-9](2)/[0-9](2)' and many other patterns to no avail.
    Also can you point me to a good thread for regular expressions in Apex?
    Thanks for any help.

    Hi,
    you can play around with oracle regular expressions at
    http://www.yocoya.com/apex/f?p=YOCOYA:REGEXP_HOME:0:
    It's an Apex application, albeit "seasoned", where you can build and test the regex and it will be 100% compatible as it runs natively, so it's not simulated on a different platform.
    Most likely the IR filter will make use of REGEXP_LIKE so you can pick that function from the menu.
    Flavio
    http://oraclequirks.blogspot.com
    http://www.yocoya.com

  • Regular expressions in Oracle 9i

    Hello,
    Does oracle 9i support regular expressions?
    I need to check if a varchar parameter contains only numbers OR letters, otherwise i should return false.
    Thanks.

    Roger22 wrote:
    Hello,
    Does oracle 9i support regular expressions?
    I need to check if a varchar parameter contains only numbers OR letters, otherwise i should return false.
    Thanks.TRANSLATE is helpful to do such a check.
    example
    WITH testdata AS
       (SELECT 'abcdef' txt FROM DUAL UNION ALL
        SELECT '1234567' txt FROM DUAL union all
        SELECT '0' txt FROM DUAL union all
        SELECT '123a4567x00' txt FROM DUAL union all
        SELECT '123.4567,00' txt FROM DUAL
    select txt,
           translate(txt,'a1234567890','a')  numbers_removed,
           translate(txt,'0abcdefghijklonopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','0')  letters_removed
    from testdata;
    TXT            NUMBERS_REMOVED     LETTERS_REMOVED
    abcdef           abcdef     
    1234567             1234567
    0                        0
    123a4567x00     ax     123456700
    123.4567,00     .,     123.4567,00One idea is to check the result for NULL or to compare the length of similiar expressions.
    Problems are usually special chars and how you want to handle that.
    Edited by: Sven W. on Aug 11, 2010 11:07 AM
    Edited by: Sven W. on Aug 11, 2010 11:07 AM

  • Regular Expression/Replace - Oracle 7.3

    Hi!
    I am trying the regular expression SQL functions of 10g to Oracle 7.3 and it seems the older version does not cover this feature yet.
    "Aaaa,Bbbb" --> "Aaaa, Bbbb"
    REPLACE *",[0-9A-Za-z]"* WITH *", "*
    The string pattern is to look for comma-punctuations that is not followed immediately by whitespacess so I can replace this with a comma followed by a whitespace.
    Any workaround for this?

    Hi,
    Welcome to the forum!
    kitsune wrote:
    Hi!
    I am trying the regular expression SQL functions of 10g to Oracle 7.3 and it seems the older version does not cover this feature yet.You're right; regular expressions only work in Oracle 10.1 and higher.
    >
    >
    "Aaaa,Bbbb" --> "Aaaa, Bbbb"
    REPLACE *",[0-9A-Za-z]"* WITH *", "*
    The string pattern is to look for comma-punctuations that is not followed immediately by whitespacess so I can replace this with a comma followed by a whitespace.
    Any workaround for this?You're best bet in Oracle 7.3 would be a user-defined function. That's a very old version; don't expect much.
    Do you know anything else about the string? For example, is there some character (say ~) that never occurs in the string? Will there ever be two (or more) whitespace characters after punctuation? What characters do you consider to be whitespace? Which are punctuation? Depending on the answers, you might be able to do something with nested REPLACE and/or TRANSLATE functions.

  • Use of Regular Expression...

    Hi ,
    How should i write a reg_exp function returning into 3 variables the parts of the following string...?????
    ("HIS"."EISAG"."DATE_INPUT")
    In other words , i would like in three variables to get the string HIS , EISAG , DATE_INPUT using the Reg_exp function
    Thanks , A lot
    Simon

    Hi sgalaxy,
    Try this.
    -- setup
    create table t ( c varchar2(30) );
    insert into t values ( '("HIS"."EISAG"."DATE_INPUT")' );
    insert into t values ( '("ABC"."DEF"."GHI")' );
    insert into t values ( '("ABC"."DEF")' );
    insert into t values ( '("ABC")' );
    insert into t values ( '("".""."")' );
    insert into t values ( null );
    insert into t values ( 'XYZ' );
    set null '(null)'
    -- v10 solution
    column result_1 format a10
    column result_2 format a10
    column result_3 format a10
    select
      2    c,
      3    regexp_replace
      4      ( regexp_substr( c, '".*?"', 1, 1 ),
      5        '"(.*?)"',
      6        '\1'
      7      ) as result_1,
      8    regexp_replace
      9      ( regexp_substr( c, '".*?"', 1, 2 ),
    10        '"(.*?)"',
    11        '\1'
    12      ) as result_2,
    13    regexp_replace
    14      ( regexp_substr( c, '".*?"', 1, 3 ),
    15        '"(.*?)"',
    16        '\1'
    17      ) as result_3
    18  from t
    19  ;
    C                              RESULT_1   RESULT_2   RESULT_3
    ("HIS"."EISAG"."DATE_INPUT")   HIS        EISAG      DATE_INPUT
    ("ABC"."DEF"."GHI")            ABC        DEF        GHI
    ("ABC"."DEF")                  ABC        DEF        (null)
    ("ABC")                        ABC        (null)     (null)
    ("".""."")                     (null)     (null)     (null)
    (null)                         (null)     (null)     (null)
    XYZ                            (null)     (null)     (null)
    -- cleanup
    drop table t;As I recently told another user, if you are interested in learning more about regular expressions I have a tutorial you might find useful at http://www.sqlsnippets.com/en/topic-10759.html .
    Message was edited to fix typos.

  • Need regular expression for oracle date format 'DD-MON-YYYY'

    Hi,
    Can anybody tell me the regular expression to validate date in 'DD-MON-YYYY'.
    My concept is i have a table with just two columns item_name and item_date
    Both fields are varchar2 and i want to fetch those records from this table which have valid date format('DD-MON-YYYY').

    If it must be a regexp, this is a starter for you, note it carries the caveats mentioned by both posters above and in the linked thread
    mkr02@ORA11GMK> with data as (select '10-jan-2012' dt from dual
      2  union all select '10-111-2012' from dual
      3  union all select 'mm-jan-2012' from dual
      4  union all select '10-jan-12' from dual)
      5  select
      6  dt,
      7  case when regexp_like(dt,'[[:digit:]]{2}-[[:alpha:]]{3}-[[:digit:]]{4}','i') then 1 else 0 end chk
      8  from data
      9  /
    DT                 CHK
    10-jan-2012          1
    10-111-2012          0
    mm-jan-2012          0
    10-jan-12            0It will not validate content, only string format.
    And to emphasis the points made in the linked thread - dates in text columns is poor design. Always.

  • Using a regular expression in String's split method

    I have a String that is delimited by commas that I would like to split into a String array. However, the problem is that it is valid that some of the elements could have embeded commas in them. These "extra" commas are always in a predefined pattern though.
    For example, the String that I want to parse may look like this (quotes omitted):
    data with spaces and tabs , more data with more spaces, now for the problem(5,9), and now some more text and spaces
    What I would like the result to be (shown below as if each element has been trimmed):
    data with spaces and tabs
    more data with more spaces
    now for the problem(5,9)
    and now some more text and spaces
    string.split("[,&&[^[\\(.,.\\)]]]");The idea being that I want to split on all commas except those that are in the pattern (5,9). Where 5 and 9 could be any integer.
    The above expression isn't working. It isn't ignoring the comma in the pattern.
    Any suggestions?
    Thanks.

    i dunno if this help...
    There is a class called the StringTokenizer class where it splits the String and delimiter up..e.g
    String s1="Hello,Welcome,Can";
    String[ ] arr=new String[3];
    To use the StringTokenizer, you create.
    StringTokenizer st=new StringTokenizer(s1,",");
    //this will split the words, hello,welcome and can into "Tokens"
    Then use this method .hasMoreTokens( )
    int i=0
    while(st.hasMoreTokens( ) ==true) {
    arr=st.nextToken( );
    i++;
    Hope this helps! =)

  • Use of Regular Expressions in BI Query Designer

    Hello All,
    For a particular requirement in Inventory, I have the following to be achieved:
    If at the input selection screen, if Plant entered is 'AB12', then it should show batches only startign with 'J' and if Plant entered is 'AB13' then the query output should show only batches with '$****K' (where * indicates any digit and $ indicates any character.
    Will I be able to achieve this at query level, since my design for Inventory is already existing.
    One way is I can always take it to a new cube and write some routines in transformation to achieve the same, but that would in essence duplicate data at multiple places.
    Request to guide me for the same.
    Thank you.
    Regards,
    Kunal Gandhi

    Hi,
    If you are able, create a Structure in your Query and add 2 Selections to it.
    Restrict 1 Selection on Plant AB12, and Batch J****** using Contains Pattern as described by Mansi. Restrict the other Selection on Plant AB13, and Batch $*****K again using Contains Pattern.
    Activate Zero Suppression on this Structure.
    When the user selects a Plant in the input, only the Selection which contains that Plant will be displayed.
    Hope this helps. Sorry it is so long after the question, I found this while looking for something else.
    Steve

  • $10 for answer: using Pattern - regular expressions and Scanner

    I'm trying to read input messages using Scanner. The messages are in format: word1 word2 number. the "number" is followed by "C null terminator" i.e. '\u0000' character.
    I tried this:
    Scanner input;
              Pattern pat = Pattern.compile("(\\w+) (\\w+) (\\d+)\u0000");
              input.useDelimiter(pat);
              while (input.hasNext(pat)) {
    The input is there and in correct format, but it hangs hasNext(pat) - as if input is not correct. What did I do wrong? Thanks in advance - thsi is urgent, I'd be glad to send you $10 for correct answer via PayPal.
    Message was edited by:
    MrM654

    Here is a Regex and a Scanner implementation.
    The price is $20 because there are 2 ways to do this.
    Plus at least a $10 courtesy tip.
    import java.util.Scanner;
    import java.util.regex.*;
    public class RegexTest{
    public static void main(String[] args){
         new RegexTest();
    public RegexTest(){
         String input = "word1 word1 1\u0000 word2 word2 2\u0000 word3 word3 3\u0000";
         Pattern pattern = Pattern.compile("(\\w+ \\w+ \\d+\\u0000)");
         Matcher matcher = pattern.matcher(input);
         while(matcher.find() == true){
         System.out.println("Match: " + matcher.group());
         String input = "word word 1\u0000 word2 word2 2\u0000 word3 word3 3\u0000";
         Pattern pattern = Pattern.compile("(\\w+) (\\w+) (\\d+)\\u0000\\s*");
        Scanner scanner = new Scanner(input);
         String result;
         while((result = scanner.findInLine(pattern)) != null){
         System.out.println("Match: " + result);
         System.out.println("Done.");
    }Edit: Changed Pattern to end with \\s* to be insensitive to ending spaces

Maybe you are looking for

  • How to access a page from another website in to the portlet

    Hai, I need this specific requirement. In a portlet that is written in jsp, i need to access another page which is running in another server.I will explain what is my requirement clearly.. In a portlet, i have to acess a page from another site, and i

  • HT1977 there is nothing like sync option in my itunes

    there is nothing like sync option in my itunes

  • XMLType

    In Oracle 10g enterprise edition there exists a data type XMLType for storing XML documents in the database. XML schema is registered by calling "call dbms_xmlschema.registerSchema" (usually including BFile). Since BFile is not available in Oracle Li

  • Render settings for presentation on computer.

    I am making a presentation of Student interviews for a local high school graduation.  I rendered it down and played it on my Macbook pro, and the words are out of sync.  I used a Canon 5d MK2 (1080p, 30 frames, 48k) It looks great and is in sync in p

  • No sounds when importing Quick Time

    I received a clip from someone and am able to open it and it p[ays fine, However, when I import it to FCP Express, The video p[ays nut there is no sound. The clip has a mpg extension.