Tips SQL - replace one OR perhaps with a regular expression?

Hi all

I have a small question. This bothers me for weeks, and I was wondering if anyone of you has another idea for this.

Imagine the following table. This is a very stupid table. But look at the sample data. I have reproduced the issue I have with the 3 files.
CREATE TABLE departments
(
  dpt_id NUMBER(10), 
  dpt_name VARCHAR2(100)
);

INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGER');
INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGERIA');
INSERT INTO departments(dpt_id, dpt_name) VALUES(1, 'NIGER.0001');

SELECT * 
  FROM departments 
 WHERE (dpt_name = 'NIGER' OR dpt_name LIKE 'NIGER.%');
If I use one AS % of NIGER, I recover as NIGERIA (which I don't want). So, instead, I use this GOLD combination and it works well. But I was wondering if it can be done without the GOLD.

Thank you

Hello

This example gets the results you requested:

SELECT    *
FROM        departments
WHERE       REGEXP_LIKE ( dpt_name
                  , '^NIGER([^[:alpha:]].*)?$'
                )
;

Describe the desired results. With only 3 or 4 lines of sample data, it is very easy to get good results for the wrong reasons.

Tags: Database

Similar Questions

  • [CS2] [JS] Replace one special character with another

    Hello

    I want to replace one specialCharacter by another in a SpecialCharacter.ForcedLineBreak, but research use only the string.

    That is right. Since you cannot enter SpecialCharacter constants in the search (and replace) the strings, you must use escape inside regular channels codes. Fortunately, these are exactly the same as in the program itself: ' ^ =' for dash, ' ^ is to the fixed space and so on. Forced line break isn't that ' ^ don't?

  • Divide a CSV with a regular Expression

    I'm working on a script that will read the CMYK values from a CSV file and add the nuances of the Swatches palette. I can easily split the CSV entering a comma (.split(",");), but I can't seem to get a regular expression to separate by commas and new lines.

    Here is the code snippet I have right now is not working:

    var fileIn = new File("/Users/brianp/Desktop/AVL-PMS-TEMP.csv");
    fileIn.open();
    var csvIn = fileIn.read();
    fileIn.close();
    
    var regEx = "/,|\\n/";
    csvRecords = csvIn.split(regEx);  
    

    I am barking the wrong tree here?

    I could change the CSV advance to find all line breaks and replace them with commas, but it looks more elegant to adapt my code for the CSV file is delivered.

    Thanks in advance!

    csvRecords = csvIn.split(/[,\n\r]/);

    This is the shortcut. To preset the regex, to leave out the quotation marks:

    var regEx = / | \n/ ;

    Better to add the CR (\r) as well.

    Use the classes of characters [...] If you can instead of alternatives (... |...), they are more effective (allegedly).

    Peter

  • Help with the Regular Expressions and regexp_replace

    Oh great guru Oracle can I can receive assistance

    I need to clean the phone numbers that have been entered in the table per_phones of Oracle e-Business. Some of the phone numbers have hyphens, some have spaces and some have tank. I just want to get out all the figures and then re - format the number.

    E.g.
    914-123-1234... out (914) 123-1234
    9141231234... new (914) 123-1234
    914 123 1234... (914) 123-1234
    MyPhone... just null
    (914)-123-1234... (914) 123-1234

    I really tried to understand the instructions of regular expressions, but for some reason, I can't understand it.

    For example:

    SQL> with sample_data as (
      2   select '914-123-1234' phone_number from dual union all
      3   select '9141231234'                from dual union all
      4   select '914 123 1234'              from dual union all
      5   select '(914)-123-1234'            from dual
      6  )
      7  select regexp_replace(
      8           regexp_replace(phone_number, '\D')
      9         , '(...)(...)(....)'
     10         , '(\1) \2-\3'
     11         ) as formatted_num
     12  from sample_data
     13  ;
    
    FORMATTED_NUM
    --------------------------------------------------------------------------------
    (914) 123-1234
    (914) 123-1234
    (914) 123-1234
    (914) 123-1234
     
    
  • Number of shaped with preg_replace Regular Expression and PHP

    Hello

    I would like to add a 'dash' after every 3 digits in a given number (10 digits). For example, 9785678941 became 978-567-894-1. How could I achieve this with regular expression using PHP preg_replace?

    Thank you.

    The next solution is based on the example of "The use of backreferences followed literals digital" published on the php.net site.

    In accordance with the $string, $pattern, $replacement nomenclature which is the php.net example use, here´s my modification:

    <>

    $string = '9785678941';

    $pattern = ' / (\\d{3})(\\d{3})(\\d{3})(\\d{1)} /';

    $replacement = ' ${1}-{2}-${3}-${4}';

    echo preg_replace ($pattern, $replacement, $string);

    ?>

  • Need help with a regular expression

    I have a Zebra printer string that I want to analyze some information, but I can't get a single regex to do.

    The string is like the following:

    ↑ FT342, 695 ^ A0N, 83, 81 ^ FH\ ^ FDS/N: [[WIDGET]] ^ FS

    ^ FT793, 1170 ^ A0N, 67, 67 ^ FH\ ^ ea FD1. Widget #00123 ^ FS

    ^ FT793, 1170 ^ A0N, 67, 80 ^ FH\ ^ ea FD2. #00456 Widget Deluxe ^ FS

    ^ FT793, 1170 ^ A0N, 67, 90 ^ FH\ ^ FD #0789 ^ FS

    I want what is in red. It will vary from one label to the label. I will use the results to show to the user what label it is printing. Who is blue only varies, if that helps anything.

    Thanks for any help!

    Here would be a way using regular expressions. Again, you have to ignore the first entry and this version will add a blank entry in the last position of the table. Wil you have more entries if your label contains more than what you have posted...

  • Analyze the Mac address with the regular expression matching

    Hello world

    I have a problem with the function of regular expression matching,

    I try to analyse the response both a query arp - a 192.168.0.15 to retrieve the MAC address of the remote IP address, I used the following regular expression: ^ ([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})$

    I wonder why should I do a subset of the first string to extract only the part of the MAC address. The regular Expression function is not able to recognize the regular expression directly in the middle of a string?

    I only works when I extracted the subset of tring right as in the picture below.

    Thanks for your replies.

    Get rid of the "^" at the beginning of your regular expression. You are ordering him to find the model at the beginning of the string.

  • Validate with a regular Expression

    Hi Experts,


    I want some regular expressions to format number as: nn/nn/nnnn

    Expressions: total 10 digits only, and / after 4 digits, as / after 7 digits.


    Test data:

    SELECT ' 1111/18/01 ' AS NUM FROM DUAL

    UNION

    SELECT ' 01 / 01/2522 ' AS NUM FROM DUAL

    UNION

    SELECT ' 222/01/01 ' AS NUM FROM DUAL

    UNION

    SELECT ' 2222/01/1 ' AS NUM FROM DUAL

    UNION

    SELECT ' 2222/0/01 ' AS NUM FROM DUAL

    UNION

    SELECT ' 2522/01 ' AS NUM FROM DUAL

    UNION

    SELECT ' 01 / / 01' AS NUM FROM DUAL.


    Desired output

    REGEXP

    -------------

    1111/18/01

    2522/01/01

    Thanks in advance

    BANNER

    ----------------------------------------------------------------

    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - production

    I hope... This does not validate a date.

    WITH the data AS

    (SELECT "1111/18/01 ' AS NUM FROM DUAL

    UNION

    SELECT ' 01 / 01/2522 ' AS NUM FROM DUAL

    UNION

    SELECT ' 222/01/01 ' AS NUM FROM DUAL

    UNION

    SELECT ' 2222/01/1 ' AS NUM FROM DUAL

    UNION

    SELECT ' 2222/0/01 ' AS NUM FROM DUAL

    UNION

    SELECT ' 2522/01 ' AS NUM FROM DUAL

    UNION

    SELECT ' 01 / / 01' AS NUM FROM DUAL.

    )

    Select num

    FROM THE DATA

    where regexp_like(num,'^\d{4}/\d{2}/\d{2}$')

    /

    HTH

  • Form validation helps with the regular Expression [a-zA-Z]

    I'm trying to use the regular expression [a-zA-Z] to allow only upper or lowercase WITHOUT SPACES. With the help of [a-zA-Z] allows space and numbers.

    Could someone give me a point in the right direction?

    Thank you!

    RGNelson wrote:

    I'm trying to use the regular expression [a-zA-Z] to allow only upper or lowercase WITHOUT SPACES. With the help of [a-zA-Z] allows space and numbers.

    Could someone give me a point in the right direction?

    Please try with the following regular expression, which should work for text entry fields 'a line' well standard.

    ^ [A-Za-z] + $

    See you soon,.

    Günter

  • stuck with a regular Expression

    Clear the javascript by RegExp train file comments: [/] [*]. + [*] [/]
    It s nice work with comments like this:
    / * blah-blah-blah * /.
    But what about like this:
    /*
    bla
    bla
    bla
    */
    How can I 'say' - ANYTHING?

    Fuffel wrote:
    > Tent clear the javascript by RegExp file comments: [/] [*]. + [*] [/]
    > It s nice work with comments like this:
    > / * blah-blah-blah * /.
    > But what about like this:
    > /*
    > blah
    > blah
    > blah
    > */
    > How I can 'say' - ANYTHING?
    >
    In find/replace in DW, it seems to work, but test it:

    \/\*[\w\W]*?\*\/

    --

    E. Michael Brandt

    www.divaHTML.com
    www.divahtml.com/Products/scripts_dreamweaver_extensions.php
    According to the standard scripts and the Dreamweaver Extensions

    www.valleywebdesigns.com/vwd_Vdw.asp
    JustSo PictureWindow
    JustSo PhotoAlbum, and alia

    --

  • Problem with regular Expression

    Hello!!
    I have a problem with the regular expression. I want to validate only one word, and second are the same. To do this, I wrote a regex

    Model p=Pattern.compile("([a-z][a-zA-Z]*)\\s\1");
    Matcher m = p.matcher ("nikhil nikhil");
    Boolean t = m.matches ();
    If (t)
    System.out.println ("it's a game");
    on the other
    System.out.println ("is no match);

    The result I get is always 'there no match. "

    Your timely help will be very appreciated.

    Concerning

    Hello.

    You are missing a slash in the regex

    Pattern p = Pattern.compile("([a-z][a-zA-Z]*)\\s\\1");
    Matcher m = p.matcher("nikhil nikhil");
    boolean t = m.matches();
    if (t) {
        System.out.println("There is a match");
    } else {
        System.out.println("There is no match");
    }
    
  • How to replace one table with another?

    I need to replace one table with another. Both tables have the same structure, primary keys, indexes, constraints, but different data (about 50 million records).
    I would like to make this replacement in line, with no passage of database in offline mode.
    There is no clause CREATE or REPLACE TABLE in Oracle unfortunely.
    I could use just DROP and ALTER TABLE RENAME instructions, but it is necessary that a user receive message error "table or view does not exist. It may be possible to block incoming requests at the moment, while old and new droppping table rename are performed?

    Thanks in advance.

    Hi again!

    You can detect normal users with session sessions $ v. A session of a normal user has a username (username of the column). Systemsessions PMON and SMON have no user name. So, you can use the following query to detect sessions, you need to kill:

    SELECT sid, serial#, username
    FROM   v$session
    WHERE type NOT LIKE 'BACKGROUND';
    

    concerning

  • How to replace one color with each other?

    Hello

    I use Photoshop Version: 2015.1.1 to change a single image.  (I use the color Mode indexed with a color table custom that I created with only 8 basic colors.)

    My bitmap has a black background and a border of a pixel wide red around its perimeter.  I want to erase that border (replacing the Red pixels with black).  I can do this with the Eraser tool, but I have to drag them all around.

    I was wondering if there is a faster way to do it.  If there is a tool that would allow me to click on the red border, they are automatically the Red pixels that form this border change to black, it would be great.  If someone can tell me that if such a tool exists, I would really appreciate it.

    I should mention that the inner part of my bitmap has red pixels I don't want to change, so I don't have to replace all the Red pixels across in your drawing.  I just replace the consecutive red pixels that form the border.

    Thanks in advance,
    Paul

    Set your foreground to black color. Select >, then edit > Stroke, 1 pixel inside, then uncheck the box.

  • Replace with complex logical regular expression

    What is the best way to replace the input string with the following rules:

    1. all sequential occurrences of two or several hyphen-symbols (symbol: '-') must be replaced by a hyphen. So, if the input string is "-" then output should be ' - '. If the entry was "a-a-a", then output remains what it is.
    2. all occurrences of two or more space sequential symbols (symbol: "" "") must be replaced by a space. If the input string is "" then exit must therefore «» If the entry was "one one one" then exit remains as it is.
    3. once the 1-2 rules are applied after the rule applies: all occurrences of the space symbol followed immediately after the hyphen-symbol or vice verse-trait of Union followed by space should be replaced with the hyphen. So, if the input string is "»" or "-" then the output should be "«»". " If the entry was 'a - a', then output remains what it is.
    4. once the 1-2-3 rules are apllied follows the rule should be applied: String beginning and symbol of the end can only be space or hyphen. Therefore, if the input string is 'a' or '-a ' or 'a' or 'a-' and then the output should be 'a '.

    All rules 1 to 4 must be apllied to the input string.
    Example of replacement logic:
    entry: 'an aa - ss-ee -'
    output: "an aa-ss-ee."

    I think that I should use the function "regexp_replace" somehow.
    This solution below does not work because it produces two consecuent dashes "-":
    with t as(
     select 'a   aa ---- ss-ee -' str from dual
    )
    select regexp_replace(str, '--','-') a from t;
    /*a   aa -- ss-ee -*/
    Can you suggest a regular expression for it?

    Maybe something like this:

    SQL> with t as(
      2   select 'a   aa ---- ss-ee -' str from dual
      3  )
      4  select rtrim(rtrim(ltrim(ltrim(
      5         regexp_replace(regexp_replace(str, '(-| )\1+','\1'), '( -|- )', ' ')
      6         , '-') , ' '), '-'), ' ') a from t;
    
    A
    -----------
    a aa  ss-ee
    

    Notice how it ends with 2 spaces in a row in the Middle, because there was a segment with '-' (space followed by '-') which was replaced by a space.

  • laptop HP pavilion touch 14: replaced defective hard drive with pre installed OS on new HDD - device not found Boot (3F0)

    Hey guys,.

    I have a pc hp pavilion touch laptop 14, which has been having a defective hard disk that the operating system was not start and the system test indicated that the hard drive contained errors.

    I replaced the hard drive with a new one and before installing the hard drive I formatted with a win installation 8.1. I thought the laptop would just start normally to win8, but gave me a screen saying:

    boot device not found please install an operating system on drive hard drive (3f0)

    The hard drive is new and I did not not how its gives me this error!

    In addition, this laptop does not seem to boot from a cd to format!

    Any ideas?

    Thank you
    Karl

    Hey BHK6,

    I found out what was wrong! It was so simple!

    I just need to make the boot inherited from the bios, like that he started directly from the hard drive and does not need of any software pre installed HP to start.

    Thanks for your help anyway

    Karl

Maybe you are looking for

  • Changes of screen images when you tapoterez

    Not sure I can explain it but like when am as a game or simply by tapping the screen hole frame changes and app icons or anything that grows, then I tap repeat once again to return to normal, anything someone please

  • Windows 8 windows install no boot

    On my Pavilion Dv7 7010: I use a dual boot system. A 500 MB sata disk 0 and a processor intel 320 128 GB SSD on disc 1. I installed the dual boot with Windows 7 original on disk 0 and the new installation of Windows 8 on DIST 1. I've upgraded to Flas

  • Windows Media Player sound only during video playback

    Windows Media Player won't PLAY VIDEO (MOVIES); ONLY SOUND CAN BE HEARD. Can someone please?  I go crazy - my windows media player will not play anything except the sound on videos (films are so far the problem).  She claims codecs are updated automa

  • Slimline drive replacement DVD s5-1204

    I was disappointed to find that the standard DVD player doesn't have Lightscribe support. I saw in the guide of upgrade there are 3 cables to the DVD player. My old Lightscribe drive has only 2 cables (SATA and power). What is the third cable? Can I

  • Removal of password of blackBerry Smartphones

    How can I delete a password for my camera so that there is no password in the system at all.