Replace the free-standing characters in String

In Oracle 10.2, I want to convert the string '1 2 3 4 5 6 def abc' to 'abc def '.

Here is the code:

1 with t as (select '1 2 3 4 5 6 def abc' double val)
2 * Select regexp_replace (val, ' (\s[0-9]\s)+ ',' ') t outval)
SQL > /.

OUTVAL
---
2 4 6 dembront

It seems that the REGEXP_REPLACE performed only one iteration of the replacement. Is there a way to get the output string 'abc def' without going through several iterations?

Hello

Welcome to the forum!

Here's one way:

SELECT     REGEXP_REPLACE ( val
                 , '((^|\s+)[0-9])+(\s|$)'
                 , '\3'
                 )     AS outval
FROM    t
;

The problem with your initial request was that space after a freestanding figure can count as a space before another freestanding figure, but the same character cannot be used to satisfy two different matches.
The query above does not replace undividual
groups of 3 characters "\s[0-9]\s"; It replaces a variable number (1 or more) of
] "groups of 2 characters, but only when the last of them is followed by an another \'s." (Acutally, I modified the problem a bit to account for several space characters before or after each free-standing figure and also to eliminate the freestanding numbers at the beginning or end of the val.) If you don't want these changes, it is easy to modify the above query).

Tags: Database

Similar Questions

  • How to replace the. in my xml or string varchar2

    Hi all

    I need to replace the "." in my code with a '_' here's my code

    Set serveroutput on
    declare
    long payloadXml;
    xDoc xmltype.
    Start
    payloadXml: = ' <? XML version = "1.0"? > < CAT. OBJMESSAGE_TYP > < FROM_USERID > abcdabcd < / FROM_USERID > < mouhamed TO_USERID > < / TO_USERID > < MESSAGE > HI THIS IS SOME MESSAGE < / MESSAGE > < / CAT. OBJMESSAGE_TYP > ';
    xDoc: = new xmltype (payloadXml);
    dbms_output.put_line(xDoc.extract('/CHAT_OBJMESSAGE_TYP/message/text()').getStringVal ());
    end;
    /


    Now, in this line I < CAT. OBJMESSAGE_TYP >, that I need to change it to
    < CHAT_OBJMESSAGE_TYP > and < / CHAT_OBJMESSAGE_TYP >

    What I have to do in the code.

    any suggestions on how to do...

    TIA

    Hello

    Assuming that he as a varchar2, you can try to use the function replace.

    select replace('','.','_')
             new_string from dual;
    
    NEW_STRING
    ----------------
    
    

    Arun-

  • replace the nth word in a string

    Oracle 10g version

    example of
    WORDS ARE SEPERATED BY ^
    
    select REGEXP_REPLACE('DEEPAK1^DEEPAK1^DEEPAK',
                             'DEEPAK',
                             'DEEPAK1',
                             3,    --nth word 
                             1) from dual;
                         
    o/p required     := DEEPAK1^DEEPAK1^DEEPAK1
    select REGEXP_REPLACE('DEEPAK1^DEEPAK1^DEEPAK1^DEEPAK',
                             'DEEPAK',
                             'DEEPAK1',
                             4,                     --nth word 
                             1) from dual; 
    o/p required     := DEEPAK1^DEEPAK1^DEEPAK1^DEEPAK1
    Published by: new learning on March 4, 2011 12:22

    If you want to replace a nth Word, it could do:

    SQL> select REGEXP_REPLACE('DEEPAK1^DEEPAK1^DEEPAK1^DEEPAK',
      2                        '[^^]+',
      3                        'DEEPAK1', 1, 4) str from dual;
    
    STR
    -------------------------------
    DEEPAK1^DEEPAK1^DEEPAK1^DEEPAK1
    

    N is 4 in the example above.

    The 4th parameter is the accident, which is one of the reasons why it did not work. The trend was also hard-coded. I don't know if it of necessary or not.

  • Error 7 open/create/replace the file to write spreadsheet String.vi

    Hello

    I try to use a CompactRIO with 9225 analog input module for measuring an analog signal.

    Version of LabVIEW is 2013 (32 bit), when I run only e VI, errot 7 has taken place.

    I'm sure that the path is correct, but the error information indicate used different path "------" is not "/", I have attached the picture.

    I don't know why this is happening, appreciate any suggestion to solve this problem.

    Thank you.

    Frank

    The cRIO-9075 doesn't have the ability to mount a Windows network share and the read/write directly with the host computer.  You'd have to do, this is the file from the FTP host (the host has to a customer, and the RT system has a server) or to run an FTP server on the host that the target can interact with (the host would then have a server, and the target's screws of the FTP client) to get the file to the location.

    -Danny

  • any easier way to replace the last character in a string?

    That's what I got:
    select SUBSTR('tjgb005dy_01_31_08',1,LENGTH('tjgb005dy_01_31_08')-1)||'1' from dual;
    
    --
    tjgb005dy_01_31_01
    and I am enough fan of it. It's ugly and it's long.
    so, I wonder if you have better ideas?

    Thank you

    Even easier:

    select regexp_replace('tjgb005dy_01_31_08','.$','1') from dual;
    
  • replace only the last 3 characters within a string

    Hi all
    I have the string "abcdef_01". How can I replace the last 3 characters with "000"? in this string, for example "_01" should be replaced by '000'. Any way to do it, without the concatenation of the original string with the last 3 characters replaced by "000"?
    Thank you

    Edited by: Roger22 the 18.10.2011 09:29

    Yes, you can...

    SELECT rpad(substr('abcdef_01',1,length('abcdef_01')-3),length('abcdef_01'),chr(dbms_random.value(32,64))
                                                                             || chr(dbms_random.value(32,64))
                                                                             || chr(dbms_random.value(32,64)))
    FROM dual;
    

    RPAD/lpad may use a third parameter that is longer than 1 character and - if the duration of param 1 + length of parameter 3 is longer that parameter 2 - truncates the result to fit the length of parameter 2.

    HTH

  • PHP - replace the slash (/) with hyphen (-)

    I started to replace the spaces, special characters, etc. with dashes. However, I can't find the proper way to replace a slash with a dash. I looked everywhere on the internet, some people, which suggests using the .htaccess file but I do not think that that suits my purpose. My code so far:

    Example: You have 1 new message (07/12/2016)

    I want to be: you-ve-got-1-new-message-12-07-2016

    <? PHP

    $message_original is $row_message ['title'];.

    $message_lower = strtolower ($message_original);

    $message_alpha = preg_replace ("/ [^ a - z0 - 9_\s-] /", "", $message_lower);

    $message_dash = preg_replace ("/ [\s-] + /","", $message_alpha ");

    $message = preg_replace ("/ [\s_] /", "-", $message_dash);

    ? >

    $string = "you have 1 new message------$! (12-07 - 2016) « ;

    $filtered = strtolower (preg_replace ('/ [\W\s\/] + / ', '-', $string));

    echo $filtered;  you-ve-Got-1-New-message-12-07-2016

    You can do it with the above simplified code. The regular expression "/ [\W\s\/] + / ' is a model group that contains three metacharacters:

    • \W matches any character that is not alphanumeric or underscore line (this is the same as [^ A-Za-z0-9_]).
    • \s matches any white space character.
    • ------/ corresponds to a forward slash.
  • Removing the non-English characters

    Hello
    I'm trying to define a regular expression that helps me to replace the non-English of a string characters.
    For example:
    BESANÇON
    and I need to get something like: BESANÇON, or BESAN * IT.

    Could someone give me some advice?
    Max has.

    You can use the convert function:

    SELECT CONVERT('BESANÇON','US7ASCII')
    FROM dual;
    
    CONVERT(
    --------
    BESANCON
    1 row selected.
    
  • Replace the last comma by "and".

    Hi all

    Please let me know is there a simple way to replace the last comma in as string with 'and '.

    for example: 1. abc, xyz, wuv must be returned to abc, xyz and wuv

    2 abc, wuv must be returned, abc and wuv

    3 abc and pqr, cuq, wuv must be returned to abc and pqr, cuq wuv

    DB version: 11.2.0.3

    Thank you

    DS

    Hello

    Here; s in one direction:

    REGEXP_REPLACE (str

    , ',([^,]*)$'

    , 'and \1 '.

    )

  • Replaces the characters in string?

    Hello

    I have a URL that contains the ' % 20' characters. Is there a way I can replace that with a space?

    I tried the following command to replace the text of the symbol "myText": ("theString" is a variable that contains the URL)

    SYM. $("myText") .html ("' + (theString.replaceAll ("% 20"," "")));

    But it does not work. However, using replace instead of the method replaceAll works but only replaces the first instance of %20 and not the rest of them?

    Can someone point me in the right direction?

    Thank you

    String url in unicode encoded in this format.

    You can also use decodeURI (string) to remove the hexadecimal values of space that is 20%

  • The analysis of the non-numeric characters in a string

    Hello

    I am communicating a robot to LabVIEW (2013) via TCP/IP and sockets. The robot is the server, and LV is the customer.

    I start with the target data in this format (in a string):

    "[0 ~ 100 ~ 0] ~ [0.96593 ~-0.25882 ~ 0 ~ 0] ~ [1 ~ 0 ~ 0 ~ 0] ~ [150 ~ 50]."

    [X, Y, Z], [Q1, Q2, Q3, Q4], [C1, C4, C6, Cx], [TCPVel, OrientVel] except replacement ',' (comma) with a ' ~ ' (tilde) because I load the target data in a spreadsheet which is a comma-delimited file.

    In LV, I take this string, the analysis of the chain and split individual items. I then pulled the singular elements as unique, 32-bit of real numbers. I take each one and convert them individually to a string, concatenate them and send them to the robot. The robot decompresses these raw bytes individually and converts them to a target of robot (position in space).

    I train (BT) check if the user has sent a bad character (non-digital) in the target data. Example of this is:

    [- 50 ~-150 ~ 0] ~ [0.96593 ~-0 ] [B2has5D882 ~ 0 ~ 0] ~ [1 ~-1 ~ 0 ~ 0] ~ [150 ~ 50]

    Now in BT, when I'm scanning the chain, these bad character becomes the entire element to zero and everything else then to zero as well. See attachment for example screen similar.

    My question is, my VI, I can analyze all non-numeric characters (that are inside the parentheses and characters that are NOT a ' ~ ' (tilde))? In this way, I can always get this item numbers and do not have this element or other items turn to zero?

    Thanks in advance for any help!

    Sorry for the question of the test

    SM


  • How you can limit the number of characters in a string attribute?

    I'm trying to fix a limit on the amount of characters that can be introduced to a string attribute.

    I saw that you can do when the user changes the web using regex mode, but how you can specify a maximum length when the user is in the form view that this currently replace the regex used in the tag on the inside: edit

    Thanks in advance,

    Andrew

    Hi André,.

    You can use the output of the editor boxes TEXTFIELD attribute.

    Just create a new attribute with the following configuration editor in the XLM:

    You can manage the size-> XSIZE and maximum number of characters-> MAXCHARS.

    I hope it helps.

    Kind regards

    Enrique

  • replacement of the same value in a string variable values

    If I have a string:

    "%s is %s that I'm talking about."

    and - I want to replace the instances with DIFFERENT values %s... What is the best way to do it.

    I thought of her analysis in separate using substr and instr chains, but I don't know if that's an exaggeration or not.

    Replace is ideal but - it replaces all occurrences of if - you can indicate just replace the first occurrence of a value, and the second with one another (i.e. If the result after replacement of the string above was supposed to be "it's the chain that I'm talking about"

    Any help is appreciated.

    Thank you

    Hello

    wtlshiers wrote:
    If I have a string:

    "%s is %s that I'm talking about."

    and - I want to replace the instances with DIFFERENT values %s... What is the best way to do it.

    Whenever you have any questions, please post CREATE TABLE and INSERT statements for some examples of data and the results desired from these data.
    Explain how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.3.0).
    See the FAQ forum {message identifier: = 9360002}

    I thought of her analysis in separate using substr and instr chains, but I don't know if that's an exaggeration or not.

    Depending on your needs, you may need to do this.

    Replace is ideal but - it replaces all occurrences of if - you can indicate just replace the first occurrence of a value, and the second with one another (i.e. If the result after replacement of the string above was supposed to be "it's the chain that I'm talking about"

    As you say, REPLACE replaces all occurrences. There is no way to say (for example) to change only the first.
    REGEXP_REPLACE, is much more flexible. There is no option for giving a specific occurrence, but you won't even have this feature. You want maybe just something like

    REGEXP_REPLACE ( '%s is the %s I am referring to'
                , '(.*)%s(.*)%s(.*)'
                , '\1This\2string\3'
                )
    

    Depends on your data and your needs.
    Are the new values (e.g. 'This' and 'chain') fixed, or if they can change from one line to the other?
    You will always have 2 (or certain known number) of ' %s in the original string?
    '%' Always report something that needs to be replaced? If not, how can you tell when he does and when it doesn't?
    Of ' always come right after "%"? If this is not the case, what are the possibilities, and what the different characters?

  • Replace the page to find number by matching the string

    Hi all

    Write the script (InDesign CS5) update the page number of the collection of the Keyterms end of this chapter. These keyterms inside this chapter applied with a character named "KT" style Here, I have collected text style applied all the "KT" with its page number appropriate by using the following code. The keyterms collection have the paragraph style "KTSET" and the page number character style "KTSET_PG". Between these two, there may be some em space or space en dash or space of Word. I just want to change these page instead of "000" number corresponding to its text (keyterms) appropriate. For example, autpatu 000 mmoloreetue must be autpatu mmoloreetue 2. I match these two strings and replace the single page number.

    KeyTerm.png

    var myDoc = app.activeDocument;
    app.findTextPreferences = null;
    app.findTextPreferences.appliedCharacterStyle = myDoc.characterStyles.item("KT");
    var myResults = myDoc.findText();
    var myFoundText = new Array;
    for (var i = 0; i < myResults.length; i++)
    {
        var r = getPage(myResults[i].characters[0]);
        myFoundText.push ([myResults[i].contents, r.name]);
    }
    alert(myFoundText)
    
    function getPage (element)
    {
        while (!(element instanceof Page || element instanceof Application))
        if (element instanceof Character)
        element = element.parentTextFrames[0].parentPage;
        else element = element.parent;
        if (element instanceof Page)
        return element;
        return null;
    }
    

    Any ideas or some suggession would be useful for me.

    Thanks in advance.

    Try this:

    app.findGrepPreferences.findWhat = "\\b (" + myText.toLowerCase () + "\\s) 000".
    app.changeGrepPreferences.changeTo = "$1" + myPage;

  • How to remove the first 11 characters of a string

    With the help of ' XML Publusher Desktop / generator model for Word / 5.6 Build 45'

    I use XML Publisher. With the help of a RTF model, to generate purchase orders by email of the purchase of the Oracle.

    The fields are drawn from the XML code generated by Oracle.

    One of the fields is the place of delivery Description field.

    Will appear in the report as follows:

    * & lt;? SHIP_TO_LOCATION_NAME? & gt; *

    When I attach a test XML file in Word and view the output, one of my test case returns a description of the site:

    DON'T code USE County Hall of Global location

    What I have to do is to remove the * DO NOT USE * according to the description of the location.

    I could do is a Find / Replace, or a substring to ignore the first 11 characters from the string. But I don't know how to do it.

    Any help would be much appreciated, because it is a production problem that is causing a bit of a small problem for us!

    Thank you very much.

    Hello
    Maybe you know this syntax :)

    Rahul

Maybe you are looking for

  • 7.6.0.105 Skype crash after forced update.

    So Skype auto just updated for me and whenever I try to open Skype it opens then crashes immediately. I tried to uninstall and reinstall restarting the computer but the same result... it doesn't let me do anything just, it hangs at startup

  • How to restore the disc on Satellite A300-1AL

    Hi, I have an A300-1AL Satellite with Windows Vista Edition Home PremiumI bought this laptop with no recovery disk. Currently C drive is messed up (impossible to install windows XP), how can I restore the system from a system pre-installed on a hidde

  • my ipod only installs on my computor how to fix?

    recently, I have restored my computor because my internet was not working, it works now but my ipod settles not on my computor he worked here before and I know that it has been installed on this computor before the date where I restored it but it say

  • while typing keyboard delay

    my keyboard beep lite, and there is a delay when typeing. You must press the keys for them to show

  • Updates to Windows not updated going just by the movements of update

    When I try to update windows it crashes just it does not update. Have tried all the fixes from Microsoft and still didn't win clean 7 install 64 3 times and now it's a little annoying... I let run for 3 hours and no difference.