Using regexp_replace

Hello, I could use some assistance in using regexp_replace for the following results:
I have string: OUTLET_ID, RETAILER_ID which is stored in variable v_pk
I want to use regexp_replace to convert to v_pk to *'OUTLET_ID' || 'RETAILER_ID'*
Any ideas?
Thank you

JesusLuvR wrote:
Hello, I could use some assistance in using regexp_replace for the following results:
I have string: OUTLET_ID, RETAILER_ID which is stored in variable v_pk
I want to use regexp_replace to convert to v_pk to *'OUTLET_ID' || 'RETAILER_ID'*'OUTLET_ID' || 'RETAILER_ID' is the same as 'OUTLET_IDRETAILER_ID'.
Are you saying you just want to get rig of the comma? You could do that with REGEXP_REPLACE, but it's more efficient to use plain old REPLACE:
REPLACE ( v_pk
Any ideas?If you wanted to change that one string into two separate strings
(1) 'OUTLET_ID' and
(2) 'RETAILER_ID'
then you could do something like this:
REGEXP_SUBSTR ( v_pk
           , '[^,]+'
           , 1
           , n
           )to get the n-th comma-delimited item in v_pk (or NULL, if there are fewer than n-1 commas in v_pk).
This assumes that there is something, if only a single space, between commas. For example
WITH    test_data   AS
     SELECT  ',BAR' AS v_pk  FROM dual
SELECT  v_pk
,     REGEXP_SUBSTR (V_PK, '[^,]+', 1, 1)     AS part_1
,     REGEXP_SUBSTR (V_PK, '[^,]+', 1, 2)     AS part_2
FROM     test_data;produces:
V_PK     PART_1     PART_2
,BAR     BARIf you want something that recognizes part_1 as being NULL, and part_2='BAR', then it's more complicated (at least in versions earlier than Oracle 11.2):
LTRIM ( REGEXP_SUBSTR ( ',' || v_pk
                      , ',[^,]*'
                      , 1
                      , n
      )

Similar Messages

  • Update invalid characters in database using regexp_replace

    I have a table in which a column has invalid characters like ` Is it possible to update this using regexp_replace with correct character '?
    Thanks

    Thank You Volder this works.
    I also need to replace if testcol has CHR(10) or CHR(11) with CHR(20) can this be done with one single regexp_replace? I don't want to use multiple regexp_replace statements one after the other.
    like
    update test set testcol = REGEXP_REPLACE(testcol, CHR(10), CHR(11) , CHR(20));
    Thank You very much!

  • Alternate without using regexp_replace function

    SELECT
      REGEXP_REPLACE(phone_number,
                     '([[:digit:]]{3})\.([[:digit:]]{3})\.([[:digit:]]{4})',
                     '(\1) \2-\3') "REGEXP_REPLACE"
                     FROM employees;
    is there any alternate without using regexp_replace function.........

    Another way
    (eliminating instr function.. as your problem focusses on a fixed length)
    WITH t AS (SELECT '112.345.6789' str FROM DUAL),
         tt AS (SELECT REPLACE (str, '.') str FROM t)
    SELECT    '('
           || SUBSTR (str, 1, 3)
           || ') '
           || SUBSTR (str, 4, 3)
           || '-'
           || SUBSTR (str, 7)
      FROM tt;
    Cheers,
    Manik.

  • How to use REGEXP_REPLACE for this scenario?

    Oracle 10G Enterprise edition
    Hi all,
    Is it possible to use REGEXP_REPLACE for multiple replaces for the give text?
    For eg.
    select replace(replace('My oracle','o','O'),'M','m') from dual
    my Oracle
    Can we do this in a single regular expresion replace or suggest me any ideas?
    Thanks all
    R

    This could be a solution
    Processing ...
    select s as string
    from (
              with reps as (
                   select 'aaa' as src, 'AAA' as dst from dual
                   union all
                   select 'bbb' as src, 'BBB' as dst from dual
              ), strings as (
                   select ' bbb a sample string aaa' as string from dual
              select *
              from reps
                   cross join strings
              model
                   partition by ( string )
                   dimension by (row_number() over(partition by string order by src ) idx)
                   measures (string as s,src,dst)
                   rules (
                        s[any] order by idx desc = replace(presentv(s[cv()+1],s[cv()+1],s[cv()]),src[cv()],dst[cv()])
    where idx = 1
    Query finished, retrieving results...
             STRING         
    BBB a sample string AAA Bye Alessandro

  • Excluding all non-printable characters using regexp_replace

    Hi All,
    I need help in excluding all non-printable charcters using regexp_replace but i was not able to exclude One special character as shown below.
    select regexp_replace('¥Tachyon-QX\_4 !? H*'' $(~!#$%^&*()?@#), BA' , '[^[:alnum:] \!\@\#\$\%\^\&\*\(\)\_\+\=\:\""\<\>\?\[\]\;\''\,\.\/\\\`\~\?\¥\] [:cntrl:]')
    from dual;
    REGEXP_REPLACE('%TACHYON-QX\_4!?H*''$(~!#$
    %Tachyon-QX\_4 !? H*' $(~!#$%^&*()?@#), BABut problem is having with special character which i am not able to print it here...having char value - 13 and ascii value - 19. I want this value to be excluded as this nonprintable charcater.
    Also i need to exclude newlines and print the output in a single line...
    Could any one help me in these two requirement..
    1. Exclude all non printable characters(Including special character having char value - 13 and ascii value - 19)
    2. Exclude all newline characters..
    Thanks,
    Yasser

    How about this?
    SQL>select regexp_replace('Tachyon-QX\_4 !? H*'' $(~!#$%^&*()?@#), BA
      2  some junk on line 2
      3  xyz line 3' , '[^[:print:]]') printable
      4  from dual;
    PRINTABLE
    Tachyon-QX\_4 !? H*' $(~!#$%^&*()?@#), BAsome junk on line 2xyz line 3

  • Using REGEXP_REPLACE to remove XML data from between XML tags

    Hello there,
    I am trying to use the REGEXP_REPLACE SQL function on a piece of XML, to remove the actual XML data from the elements. My end goal is to end up with a comma-delimited list of XML element names. As part of the first step, I just want to rip out all the actual data.
    I tested the following query, and it initially appeared to work:
    SELECT REGEXP_REPLACE('&gt;THIS IS A TEST&lt;',
                          '&gt;([[:alnum:]]\s|\S)*&lt;',
                          '&gt;&lt;' ) AS test_result
      FROM dual;Unfortunately, when I applied this to a full XML string, it didn't work. Here is the test query I used:
    SELECT REGEXP_REPLACE('&lt;ROW&gt;&lt;TEST_ELEMENT1&gt;123&lt;/TEST_ELEMENT1&gt;&lt;TEST_ELEMENT2&gt;THIS IS A TEST!&lt;/TEST_ELEMENT2&gt;&lt;/ROW&gt;',
                          '&gt;([[:alnum:]]\s|\S)*&lt;',
                          '&gt;&lt;') AS test_result
      FROM dual;I ended up with the following output:
    *&lt;ROW&gt;&lt;/ROW&gt;*
    What I was trying for was:
    *&lt;ROW&gt;&lt;TEST_ELEMENT1&gt;&lt;/TEST_ELEMENT1&gt;&lt;TEST_ELEMENT2&gt;&lt;/TEST_ELEMENT2&gt;&lt;/ROW&gt;*
    If you're reading this and you're a Posix RegExp Guru, please could you let me know exactly where I'm going wrong? RegExps are not my strong point, but I'd like to get better at them.

    jmcnaug2 wrote:
    Just out of interest, how would you go about writing the XQuery function so that it returns the actual XML Element values in comma-delimited form (This is Oracle Canonical XML, so has a very basic layout)? ;)Do you mean like this ?
    SQL> SELECT xmlquery(
      2    'for $i in $d/ROWSET/ROW
      3     return string-join($i/*, ",")'
      4    passing dbms_xmlgen.getXMLType('SELECT employee_id, last_name, first_name FROM employees WHERE rownum < 10') as "d"
      5    returning content
      6  ).getClobVal() as csv
      7  FROM dual;
    CSV
    100,King,Steven
    101,Kochhar,Neena
    102,De Haan,Lex
    103,Hunold,Alexander
    104,Ernst,Bruce
    105,Austin,David
    106,Pataballa,Valli
    107,Lorentz,Diana
    108,Greenberg,Nancy
    SQL>

  • Using REGEXP_REPLACE in oracle 10g for repetition of the source string

    Hello all,
    I kept trying but unsuccessful, Here is what i would like.
    I have a source string and i would like that to be repeated in the way i would like.
    Let say, i have about 50 tables to write update statements for each with the same table from another database.
    So, I would like to take the columns i need for each table, use a regular expression and create a set clause.
    FOR EXAMPLE
    say, a table has 3 columns
    Source string is 'TABLE_COLUMN_1_ID,TABLE_COLUMN_2_VALUE,TABLE_COLUMN_3_DESC'
    I would like to use regular expressions in 10g and get this
    desired o/p
    'TABLE_COLUMN_1_ID = TABLE_COLUMN_1_ID,TABLE_COLUMN_2_VALUE = TABLE_COLUMN_2_VALUE,TABLE_COLUMN_3_DESC = TABLE_COLUMN_3_DESC'
    I thought s its easy with my knowledge of expressions but still struggling.
    Any help is greatly appreciated.
    Thanks.

    Something like this ?
    SELECT REGEXP_REPLACE('TABLE_COLUMN_1_ID,TABLE_COLUMN_2_VALUE,TABLE_COLUMN_3_DESC',
                          '([^,]+)', ' \1 = \1') x
    FROM DUAL;
    X
    TABLE_COLUMN_1_ID = TABLE_COLUMN_1_ID, TABLE_COLUMN_2_VALUE = TABLE_COLUMN_2_VALUE, TABLE_COLUMN_3_DESC = TABLE_COLUMN_3_DESC

  • SQL Loader Error using regexp_replace

    Hi Guys,
    i am trying to using sql loader to load data and one column in control file is
    x1 POSITION(718:725) DATE "YYYYMMDD" NULLIF FI_CLM_RCPT_DT = BLANKS,
    XYZ POSITION(736:745) CHAR "regexp_replace(substr(:XYZ,1,9),\'[^1|Y|N|U|W]\',\' \')||regexp_replace(substr(:XYZ,10,1),\'[^Z]\', \' \'))")
    But at last part i am getting error
    SQL*Loader-951: Error calling once/load initialization
    ORA-02373: Error parsing insert statement for table TDESAI_DBA.HAJI_CLM_A.
    ORA-00933: SQL command not properly ended
    I know the error is with XYZ Column but where. Or am i doing something wrong?
    Can you guys help me

    Please see the discussion on the Semantic Technologies OTN form at SQL*Loader error 350 using SDO_RDF_TRIPLE_S constructor

  • How to used REGEXP_REPLACE  for replace part of string ?

    hi
    How can i replace part of string as following , i want to replace space in date by "-"
    SELECT
    REGEXP_REPLACE(upper('Daivd bought stuff by 2000 USD on 12 Sep 2012 from KL and left kl on 20 Sep 2012'),
    '[0-9]{1,2}[^0-9](JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC)[^0-9][0-9]{4}',
    ' ','-') "REGEXP_REPLACE"
    FROM DUAL;
    the output will be like this
    Daivd bought stuff by 2000 USD on 12-Sep-2012 from KL and left kl on 20-Sep-2012
    regards

    I thought the questions is answered.
    Your code will not work, because the alternate expression applies only to the four digit year and the month.
    If you want to recognize both date formats with one expressions, you have to group the complete expressions.
    The disadvantage of this would be, that the backreferences would not work in the same way because you would have more groups.
    I advice to use two separate regular expressions for this task.
    Take a look at the following example if you simply want to fill the gaps with -:
    with yourtable as
      select 'Daivd bought stuff by 2000 USD on 12 Sep 2012 from KL and left kl on 20 Sep 2012' text from dual union all
      select 'Daivd bought stuff by 2000 USD on Sep, 20 2012 from KL and left kl on Sep, 20 2012' text from dual 
    SELECT
    REGEXP_REPLACE(
    REGEXP_REPLACE(text,
    '([0-9]{1,2}) (JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC) ([0-9]{4})','\1-\2-\3',1,0,'i'),
    '(JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC), ([0-9]{1,2}) ([0-9]{4})','\1-\2-\3',1,0,'i') regexp_replace
    FROM yourtable;If you want same output-format for both date formats you could use this:
    with yourtable as
      select 'Daivd bought stuff by 2000 USD on 12 Sep 2012 from KL and left kl on 20 Sep 2012' text from dual union all
      select 'Daivd bought stuff by 2000 USD on Sep, 20 2012 from KL and left kl on Sep, 20 2012' text from dual 
    SELECT
    REGEXP_REPLACE(
    REGEXP_REPLACE(text,
    '([0-9]{1,2}) (JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC) ([0-9]{4})','\1-\2-\3',1,0,'i'),
    '(JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC), ([0-9]{1,2}) ([0-9]{4})','\2-\1-\3',1,0,'i') regexp_replace
    FROM yourtable;Edited by: hm on 25.09.2012 22:00

  • How to get the opposite(not true) of a pattern using Regexp_replace

    Hi,
    In the following simple sql query....all occurences of 'a' are replaced by the next character...
    SQL> select regexp_replace('Palaio Faliro','[a]{1}') from dual;
    REGEXP_REPLACE('PALAIOFALIRO',
    Plio FliroIs it possible to get the opposite of this pattern... namely except for the 'a' character , all others to be replaced by their next character in the above string....
    So , to get....aaa(i think... as only the 'a' character is not going to be replaced...)
    Thanks...
    Sim

    scott> select regexp_replace('Palaio Faliro','[^a]{1}') from dual;
    REG
    aaa

  • Use REGEXP_REPLACE as advanced initcap function?

    Hi,
    I wan't to convert a string "bygger'n" to "Bygger'n", is it possible to do something like this with regexp_replace?
    "bygger'n" is just meant as an example, I want to replace all matching patterns with lowercase letters.
    Oracle does not seem to consider lower/upper-functions for the replace of patterns:
    SQL> select regexp_replace(initcap('bygger''n'), '(''[[:alnum:]])', lower('\1')) try_lower
      2  ,      regexp_replace(initcap('bygger''n'), '(''[[:alnum:]])', ' \1 ') spaces
      3  from   dual
      4  /
    TRY_LOWE SPACES
    Bygger'N Bygger 'NRegards
    Haavard

    If you are on 10g you can do it with a Java Stored Procedure that handles regular expressions with a powerful API. Take a look at the Matcher class.
    http://www.regular-expressions.info/java.html
    http://www.javaworld.com/javaworld/jw-02-2003/jw-0207-java101.html
    create or replace java source named MyInitcap as
    import java.util.regex.*;
    class MyInitcap {
         public static String firstUpper(String s) {
              return Character.toUpperCase(s.charAt(0))+s.substring(1).toLowerCase();
         public static String initcap(String input) {
              Pattern p = Pattern.compile ("((\\w|')+)");
              Matcher m = p.matcher (input);
              StringBuffer sb = new StringBuffer ();
              while (m.find ())
                   m.appendReplacement (sb, firstUpper(m.group()));
              m.appendTail (sb);
              return sb.toString();
    create or replace function my_initcap (
              string in varchar2
         )return varchar2
    as language java name 'MyInitcap.initcap(java.lang.String) return java.lang.String';
    /And then
    Processing ...
    with t as (select 'FIRSTNAME O''MALLEY' col1
                 from dual
                union
               select 'FIRST''NAME  TEH''TE'
                 from dual
                union
               select 'FORMAT ME BYGGER''N'
                 from dual
                union
               select 'OLD MCDONALD'
                 from dual
                union
               select 'EVEN OL''DER MACDONALD'
                 from dual
    select t.col1 source
         , my_initcap(col1) formatted
      from t
    Query finished, retrieving results...
            SOURCE              FORMATTED                                   
    EVEN OL'DER MACDONALD Even Ol'der Macdonald  
    FIRST'NAME  TEH'TE    First'name  Teh'te    
    FIRSTNAME O'MALLEY    Firstname O'malley     
    FORMAT ME BYGGER'N    Format Me Bygger'n     
    OLD MCDONALD          Old Mcdonald          
    5 row(s) retrievedBye Alessandro

  • Help in using  regexp_replace function.

    Hi everyone,
    i have a string something like this..
    varchar2(100) := 'SUBF1.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1'
    i want to replace the FIRST OCCURANCE of SUBF1 with some other string.
    EX:
    For the above string if i replace the FIRST OCCURANCE of SUBF1 with 'Hi' the output gonna be like this
    OUTPUT : 'Hi.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1'
    Sorry if this question had asked previously in this FORUM.
    Thanks in advance..
    phani

    test@ora>
    test@ora>
    test@ora> --
    test@ora> with t as (
      2    select 'SUBF1.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1' as x from dual)
      3  --
      4  select x,
      5         regexp_replace(x,'SUBF1','Hi',1,1) as modx
      6  from t;
    X                                          MODX
    SUBF1.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1 Hi.AAAAAAAAAAAAA.SUBF1.BBBBBBBBBB.SUBF1
    1 row selected.
    test@ora>
    test@ora>isotope

  • Howto escape special characters if using regexp_replace & regexp_substr

    hello experts,
    following test case
    insert into querytest1 (d) values
    ('#1(170):[{"type":"FACEBOOK","count":0,"lastEdition":1382627403299},{"type":"GOOGLE","count":0,"lastEdition":1381825285002},{"type":"EMAIL","count":2,"lastEdition":1381826322925}] #2(0):  #3(5):-3141 #4(5):-3141 #5(5):21804 #6(7):3890750 #7(3):s11');
    select regexp_replace(d, REGEXP_SUBSTR (REGEXP_SUBSTR(d, '[^ ]+', 1, 1), '[^:]+', 1, 2 ),'') from querytest1;
    ERROR at line 1:
    ORA-12726: unmatched bracket in regular expression
    proof that []{} special characters are the problem:
    delete from querytest1;
    commit;
    -- insert data without special characters
    insert into querytest1 (d) values ('#1(170):"type":"FACEBOOK","count":0,"lastEdition":1382627403299,"type":"GOOGLE","count":0,"lastEdition":1381825285002,"type":"EMAIL","count":2,"lastEdition":1381826322925] #2(0):  #3(5):-3141 #4(5):-3141 #5(5):21804 #6(7):3890750 #7(3):s11');
    select regexp_replace(d, REGEXP_SUBSTR (REGEXP_SUBSTR(d, '[^ ]+', 1, 1), '[^:]+', 1, 2 ),'') from querytest1;
    REGEXP_REPLACE(D,REGEXP_SUBSTR(REGEXP_SUBSTR(D,'[^]+',1,1),'[^:]+',1,2),'')
    #1(170)::"FACEBOOK","count":0,"lastEdition":1382627403299,:"GOOGLE","count":0,"lastEdition":1381825285002,:"EMAIL","count":2,"lastEdition":1381826322925,:"EMAIL","count":2,"lastEdition":1381826322925] #2(0):  #3(5):-3141 #4(5):-3141 #5(5):21804 #6(7):3890750 #7(3):s11
    so now it works because there are no special characters []{}
    is there a way to escape them?
    thank you in advance.

    oraman wrote:
    ok you're right I explain from the beginning.
    create table t (q varchar2(4000), d varchar2(4000), result varchar2(4000));
    insert into t (q,d) values ('#1(170):[{"type":"FACEBOOK","count":0,"lastEdition":1382627403299},{"type":"GOOGLE","count":0,"lastEdition":1381825285002},{"type":"EMAIL","count":2,"lastEdition":1381826322925}] #2(0):  #3(5):-3141 #4(5):-3141 #5(5):21804 #6(7):3890750 #7(3):s11',
    'UPDATE mytable set value=:1 , valuec=:2 , longvalue=:3 , doublevalue=:4  WHERE productattrnameid=:5  AND productid=:6   AND context=:7');
    I would like to get the following:
    select result from t;
    UPDATE mytable set value='[{"type":"FACEBOOK","count":0,"lastEdition":1382627403299},{"type":"GOOGLE","count":0,"lastEdition":1381825285002},{"type":"EMAIL","count":2,"lastEdition":1381826322925}]' , valuec=NULL , longvalue=-3141 , doublevalue=-3141  WHERE productattrnameid=21804  AND productid=3890750   AND context='s11';
    the logic is to get the auditing data as ready to execute queries.
    It looks you want to include every parameter where parameter is a pattern prefixed by #p1(lenght):param_value #p2(lenght):param_value etc.
    Something like this?
    set line 1000
    col txt format a200
    with querytest1 as
    select '#1(170):[{"type":"FACEBOOK","count":0,"lastEdition":1382627403299},{"type":"GOOGLE","count":0,"lastEdition":1381825285002},{"type":"EMAIL","count":2,"lastEdition":1381826322925}] #2(0):  #3(5):-3141 #4(5):-3141 #5(5):21804 #6(7):3890750 #7(3):s11' d
      from dual
    select 'UPDATE mytable set value='''|| nvl(trim(regexp_substr (d,'#\d+\(\d+\):([^# ]+)', 1, 1, null, 1 )), 'NULL')||''''
           || chr(10) ||'     , valuec='||nvl(trim(regexp_substr (d,'#\d+\(\d+\):([^#]+)', 1, 2, null, 1 )), 'NULL')
           || chr(10) ||'     , longvalue='|| nvl(trim(regexp_substr (d,'#\d+\(\d+\):([^#]+)', 1, 3, null, 1 )),'NULL')
           || chr(10) ||'     , doublevalue='||nvl(trim(regexp_substr (d,'#\d+\(\d+\):([^#]+)', 1, 4, null, 1 )),'NULL') 
           || chr(10) ||' WHERE productattrnameid='||regexp_substr (d,'#\d+\(\d+\):([^#]+)', 1, 5, null, 1 )
           || chr(10) ||'   AND productid='||regexp_substr (d,'#\d+\(\d+\):([^#]+)', 1, 6, null, 1 )  
           || chr(10) ||'   AND context='''||regexp_substr (d,'#\d+\(\d+\):([^#]+)', 1, 7, null, 1 )||''';' txt
      from querytest1;
    Result:
    TXT                                                                                                                                                                                                    
    UPDATE mytable set value='[{"type":"FACEBOOK","count":0,"lastEdition":1382627403299},{"type":"GOOGLE","count":0,"lastEdition":1381825285002},{"type":"EMAIL","count":2,"lastEdition":1381826322925}]'  
         , valuec=NULL                                                                                                                                                                                     
         , longvalue=-3141                                                                                                                                                                                 
         , doublevalue=-3141                                                                                                                                                                               
    WHERE productattrnameid=21804                                                                                                                                                                         
       AND productid=3890750                                                                                                                                                                               
       AND context='s11';                                                                                                                                                                                  
    1 row selected.
    I have a problem formatting the output in the forum but I hope you get it.
    Regards.
    Alberto

  • REGEXP_REPLACE and backslashes ... possible bug in 10g?

    I have had a problem with backslashes in the replacement text of the REGEXP_REPLACE function.
    You see, I'm using REGEXP_REPLACE to implement a "replace whole words only" function. The implementation consists of four find-replace pairs constructed as follows (with the <find> and <replace> taking the place of the actual strings):
    update X set Y = REGEXP_REPLACE (REGEXP_REPLACE (REGEXP_REPLACE (REGEXP_REPLACE ('([^[:alnum:]])<find>([^[:alnum:]])', '\1<replace>\2'), '^<find>([^[:alnum:]])', '<replace>\1'), '([^[:alnum:]])<find>$', '\1<replace>'), '^<find>$', '<replace>')
    The problem comes in when <replace> contains backslashes. According to the documentation (the Oracle Database SQL Reference, section 7) suggests that \ must appear as \\ in the replacement string.
    However, I'm finding that you use \\ to represent \ in the replacement only if the find string does not contain groups (the parenthesized expressions). Is that how it's supposed to work? We're using 10g.
    Here is a small SQL script to illustrate the behaviour I'm seeing. It is supposed to replace "is" with "\". I expected the expression for OUTPUT1 to be correct, but it seems that the expression for OUTPUT2 works (notice that the second expression is different in only ONE CHARACTER from the first).
    create table REGEXP_TEST ( INPUT VARCHAR2(15), OUTPUT1 VARCHAR2(15), OUTPUT2 VARCHAR2(15), EXPECTED VARCHAR2(15), INCORRECT VARCHAR2(15)) ;
    insert into REGEXP_TEST (INPUT, EXPECTED, INCORRECT) values ('This is a test', 'This \ a test', 'This \\ a test');
    insert into REGEXP_TEST (INPUT, EXPECTED, INCORRECT) values ('This is', 'This \', 'This \\');
    insert into REGEXP_TEST (INPUT, EXPECTED, INCORRECT) values ('is a test', '\ a test', '\\ a test');
    insert into REGEXP_TEST (INPUT, EXPECTED, INCORRECT) values ('is', '\', '\\');
    update REGEXP_TEST set OUTPUT1 = REGEXP_REPLACE (REGEXP_REPLACE (REGEXP_REPLACE (REGEXP_REPLACE (INPUT, '([^[:alnum:]])is([^[:alnum:]])', '\1\\\2'), '^is([^[:alnum:]])', '\\\1'), '([^[:alnum:]])is$', '\1\\'), '^is$', '\\');
    update REGEXP_TEST set OUTPUT2 = REGEXP_REPLACE (REGEXP_REPLACE (REGEXP_REPLACE (REGEXP_REPLACE (INPUT, '([^[:alnum:]])is([^[:alnum:]])', '\1\\\2'), '^is([^[:alnum:]])', '\\\1'), '([^[:alnum:]])is$', '\1\\'), '^is$', '\');
    select * from REGEXP_TEST;

    Hello Darren,
    You're right, the behaviour does seem a little odd:
    SQL> select regexp_replace('X', 'X', '\\') from dual;
    SQL> select regexp_replace('X', '(X)', '\\') from dual;
    What I suggest is you rewrite your query as a single regular expression thus removing the 3 extra calls to REGEXP_REPLACE:
    update REGEXP_TEST
    set OUTPUT1 = REGEXP_REPLACE (INPUT, '(^|[^[:alnum:]])is([^[:alnum:]]|$)', '\1\\\2');
    This should solve your problem for now.
    Regards.

  • Using regular expressions to get a customized output

    Hi,
    I have a string/varchar variable with the data ',a,b,c,' in it.
    I want the display as follows:
    a
    b
    c
    I would like to get the similar output using regular expressions.
    How do I get this output using REGEXP_REPLACE or REGEXP_SUBSTR?
    Please do the needful.
    Thanks & Regards,
    Rakshit

    I remember that, however if we look closer, that one has a little flaw: The 2nd row should be null, because ",," indicates an empy field. The MODEL clause solution works just fine in this case:
    with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)
    -- end of sample data
    SELECT col_new
      FROM t
    MODEL
       PARTITION BY (ROWNUM rn)
       DIMENSION BY (0 dim)
       MEASURES(col1, col1 col_new)
       RULES ITERATE(99) UNTIL (ITERATION_NUMBER = LENGTH(REGEXP_REPLACE(col1[0], '[^,]')))
                    (col_new[ITERATION_NUMBER] = REPLACE(REGEXP_SUBSTR(col1[0], '(^|,)[^,]*', 1, ITERATION_NUMBER+1), ','))
    COL_NEW                                                                                                                                                                  
    aaaa                                                                                                                                                                     
    bbbb                                                                                                                                                                     
    cccc                                                                                                                                                                     
    dddd                                                                                                                                                                     
    eeee
    ffff
    7 Zeilen ausgewählt.Update: I had this nagging feeling that I missed something, and there it was. If you want to see what the problem with my solution is, change the example to
    with t as (select ',aaaa,,bbbb,cccc,dddd,eeee,ffff' col1 from dual)So I went back and tried to fix BlueShadows approach. Here it is:
    with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' txt from dual)
    -- end of sample data
    SELECT REPLACE(REGEXP_SUBSTR(',' || txt, ',[^,]*', 1, level), ',') col_new
      FROM t
      CONNECT BY level <= length(regexp_replace(txt,'[^,]*'))+1
    ;C.

Maybe you are looking for

  • Stock mouvement 351 from purchase order : committed quantity

    Hello, I currently have MRP running for a division. It creates purchase requisitions with the quantity necessary to transfer. In ME59N there is a check availability between the purchase requisition and the purchase order (transfer between division).

  • Freetalk Connect•Me adapter

    Hi, I'm interested in how the adapter works. I tried looking for reviews and setup guides to no avail. From my understanding, the adapter gives a regular phone the ability to be used on Skype. However I have a few questions regarding the adapter. 1.

  • Can someone send me a link to elements 11 please

    i bought a new i mac and i can't seem to be able to find a link to download elements 11

  • Anonymous Client - How Does the Service Endpoint Know Which Operation

    I am using a client (Axis2) to invoke a service through their Anonymous capabilities. When this is done, you create a ServiceClient with the default constructor and call one of its methods based on the MEP that I want to perform. In doing this, the S

  • Default local calendar deleted after removing Mail Exchange

    Hi, I have a problem with my 4S. I just removed my calendar sync from my iPhone and now I can't create any appointments. I have no offline local calendar in my iPhone anymore. When I turn iCould on I have the iCloud calendars, but I want a local iPho