REGEXP_LIKE Confusion

Hi I want to create a function using regexp_like.

In seeking,

SQL> WITH t1 AS (SELECT '[email protected]' email FROM DUAL
  2              UNION
  3              SELECT '[email protected]' email FROM DUAL
  4              UNION
  5              SELECT 'test3@[email protected]' email FROM DUAL)
  6  SELECT email
  7    FROM t1
  8   WHERE REGEXP_LIKE (EMAIL,
  9                      '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$');


EMAIL
---------------------
[email protected]
[email protected]

Now i trying to create function on that.

declare

  p BOOLEAN

BEGIN

  P  := REGEXP_LIKE ('test3@[email protected]', '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$');

  IF TRUE THEN

     DBMS_OUTPUT.PUT_LINE('T');

  ELSE

     DBMS_OUTPUT.PUT_LINE('F');

  END IF;

END;

But always i get answer 'T'.....but if u see this email is invalid so i have to get 'F' insted of 'T'

So may i know why i get 'T' always ??

Thanks

Swapnil

First of all, you can not assign regexp_like<...> to a variable.

Secondly you always compare IF (TRUE) which means its always true forever, he penetrates inside and Don 't' on the screen.

Maybe something like that is what you are looking for.

set serveroutput on

DECLARE
   p   NUMBER;
BEGIN
   SELECT 1
     INTO p
     FROM DUAL
    WHERE REGEXP_LIKE ('test3@[email protected]',
                       '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$');
   IF (p = 1)
   THEN
      DBMS_OUTPUT.PUT_LINE ('T');
   END IF;
EXCEPTION
   WHEN NO_DATA_FOUND
   THEN
      DBMS_OUTPUT.PUT_LINE ('F');
END;

See you soon,.

Manik.

Tags: Database

Similar Questions

  • Work with REGEXP_LIKE

    Hello
    I am confused with the following example of REGEXP_LIKE
    create table test_like (nm1 varchar2(11))
    
    insert into test_like values ('AUS' ) ;
    insert into test_like values ('ATS' ) ;
    
    select * from test_like where regexp_like(nm1,'*AT*');
    The statement SELECT abvoe gives 2records. I don't expect that one folder must be returned by the query above
    Please give me a hint on this

    Thank you

    You don't need *.

    select * from test_like where regexp_like(nm1,'AT');
    

    or

    SQL> select * from test_like where regexp_like(nm1,'.*AT.*');
    
    NM1
    -----------
    ATS
    

    Published by: JAC on May 22, 2013 16:19

    Your model (* AT *) means, whatever it is - A then - then T zero or more times.

  • Help REGEXP_LIKE

    Hello

    Browsed the web looking for assistance using the syntax REGEXP_LIKE. Did not have a precise answer, but I think that I wrote my own correct and just wanted to get validated by other users.


    Running Oracle 10.2

    Sample data:
    create table test(data varchar2(10));
        insert into test values('01W00012');
        insert into test values('50321070');
        insert into test values('A1391010');
        insert into test values('ZZ260010');
        insert into test values('29374C01');
        insert into test values('A938523A');
        insert into test values('23W48AC3');
        insert into test values('DKFUGHCK');
        insert into test values('09W00032');
        insert into test values('94857283');
        insert into test values('AB-29348');
        insert into test values('98W-8923');
        insert into test values('0AW00005');
        insert into test values('04300W05');
        commit;
    What I'm doing:
    I have a table that contains millions of work orders. They are all of length 8. I want to find all the good work where the first 2 characters are a number only, the third character is a 'W' and the last 5 characters are only numbers. Another thing I want to throw. I think that I came up with an expression of work... but I'm always hesitant when he runs against millions of rows. That's what I did:
    select * from test
        where regexp_like(data, '(^[0-9]{2}W{1}[[:digit:]]{5})');
    There are has exactly 2 occurrences of room above that match the criteria that I try to answer.
    This expression is correctly written?

    Any help would be appreciated... reg expressions always make my turn head :(

    Hello

    dvsoukup wrote:
    Running Oracle 10.2

    Samples:...

    Thanks for posting this; It is really useful!

    What I'm doing:
    I have a table that contains millions of work orders. They are all of length 8. I want to find all the good work where the first 2 characters are a number only, the third character is a 'W' and the last 5 characters are only numbers. Another thing I want to throw. I think that I came up with an expression of work... but I'm always hesitant when he runs against millions of rows. That's what I did:

    select * from test
    where regexp_like(data, '(^[0-9]{2}W{1}[[:digit:]]{5})');
    

    There are has exactly 2 occurrences of room above that match the criteria that I try to answer.
    This expression is correctly written?

    Yes, it's a good regular expression. However, one very important thing about regular expressions is that you should only use the when you actually need. In this case, you can get the results you want more effectively and at least as easily, without regular expressions. Here's one way:

    SELECT  *
    FROM     test
    WHERE   TRANSLATE ( data
                , '012345678'
                , '999999999'
                )          = '99W99999'
    ;
    

    It will be more effective than the use of REGEXP_LIKE, and it seems that efficiency is important in this case.

    If you really want to use a regular expression, there are a few things you can do to make it more clear. (With regular expressions, nothing overlooked.)
    (a) If you are sure that the data is always exactly 8 characters, then you don't need the ^ anchor at the beginning. If you want the regular expression to verify that the length is 8 characters, then keep the ^ anchor at the beginning, but also, to use an anchor $ at the end, as in the example below. As you posted it, the expression is TRUE when data are greater of 8 characters, as long the first 8 characters fit the pattern.
    (b) [0-9] is equivalent to [[: digit:]]. Either it's good, but I find it confusing to use both in the same expression. Use one or the other in both places.
    (c) {1} is the default value. I would say just 'W' instead of 'W {1} '.
    (d) you don't need parentheses in this expression. If parentheses are not required, but they improve the clarity, then it's OK to include them. In this case, I don't think they add anything.

    There are has exactly 2 occurrences of room above that match the criteria that I try to answer.

    It helps if you post exactly what results you want. For example:

    DATA
    ----------
    01W00012
    09W00032
    

    In this case, I found your description very clear, but it does not hurt to post actual results anyway.

    This expression is correctly written?

    You can consider writing this way, especially if you think you'll need to debug:

    SELECT  *
    FROM      test
    WHERE      REGEXP_LIKE ( data
                  , '^'          || -- beginning of string
                    '[0-9]{2}'     || -- 2 digits
                    'W'          || -- a capital W
                    '[0-9]{5}'     || -- 5 more digits
                    '$'             -- end of string
                  )
    ;
    

    As previously mentioned, you only need the ^ and $ if you are not sure that all the strings are exactly 8 characters.

    ... reg expressions always make my head spin

    All the more reason to use TRANSLATE.

    Published by: Frank Kulash, 26 July 2012 14:42

  • Address with REGEXP_LIKE

    Hey all,.
    I am a newbie to REGEXP and have a problem where I have 2 spatial tables, for each object in table1 and do a SDO_NN to find the nearest 2 objects in table2. I also have an address for each spatial table column. I'm trying to compare Address1 (from table1) to the two addresses (address2 from table2) to find the most likely candidate to match.
    After reading REGEXP it seemed the REGEXP_LIKE was probably best way to reach my matches.
    What I came up with works many times, but not always and I don't quite understand.

    Here's an example where I do not understand what is happening when I used REGEXP_LIKE like this
    REGEXP_LIKE (Address1, replace (address2,' ',' |'))
    SELECT 
      id,  
      address1,
      address2,
      CASE
        WHEN address1=address2 THEN 'EXACT MATCH'
        WHEN REGEXP_LIKE(address1,replace(address2,' ','|')) THEN 'PROBABLE MATCH'
        ELSE 'NON MATCH'
      END AS TEST
    FROM
      (
      SELECT
        1 ID, '930 OLD STEESE HWY' address1, '930 OLD STEESE HWY' address2
      FROM
        DUAL  
      UNION SELECT
        3 ID, '930 OLD STEESE HWY' address1, '920 OLD STEESE HWY' address2
      FROM
        DUAL    
      UNION SELECT
        3 ID, '930 OLD STEESE HWY' address1, '99 COLLEGE RD' address2
      FROM
        DUAL    
      UNION SELECT
        4 ID, '930 OLD STEESE HWY' address1, '80 5TH ST' address2
      FROM
        DUAL      
      );
    
    RESULTS
    ID ADDRESS1            ADDRESS2            TEST
    -- ------------------  ------------------  --------------
    1  930 OLD STEESE HWY  930 OLD STEESE HWY  EXACT MATCH
    2  930 OLD STEESE HWY  920 OLD STEESE HWY  PROBABLE MATCH
    3  930 OLD STEESE HWY  99 COLLEGE RD       NON MATCH
    4  930 OLD STEESE HWY  80 5TH ST           PROBABLE MATCH
    I am really confused about the 4th line in the results?
    Thoughts and or suggestions?
    Enjoy it!
    See you soon,.
    Eric

    Second and fourth row match because there is a word in address2 who is present (at least as a substring) in Address1: for fourth ST is STEESE substring.

    If you want a PROBABLE MATCH when there is a Word now as a word in Address1 address2, you can change this way:

    SQL> SELECT
      2    id,
      3    address1,
      4    address2,
      5    CASE
      6      WHEN address1=address2 THEN 'EXACT MATCH'
      7      WHEN REGEXP_LIKE(address1,'(^| )'||replace(address2,' ','|')||'($| )') THEN 'PROBABLE MATCH'
      8      ELSE 'NON MATCH'
      9    END AS TEST
     10  FROM
     11    (
     12    SELECT
     13      1 ID, '930 OLD STEESE HWY' address1, '930 OLD STEESE HWY' address2
     14    FROM
     15      DUAL
     16    UNION SELECT
     17      3 ID, '930 OLD STEESE HWY' address1, '920 OLD STEESE HWY' address2
     18    FROM
     19      DUAL
     20    UNION SELECT
     21      3 ID, '930 OLD STEESE HWY' address1, '99 COLLEGE RD' address2
     22    FROM
     23      DUAL
     24    UNION SELECT
     25      4 ID, '930 OLD STEESE HWY' address1, '80 5TH ST' address2
     26    FROM
     27      DUAL
     28    );
    
            ID ADDRESS1           ADDRESS2           TEST
    ---------- ------------------ ------------------ --------------
             1 930 OLD STEESE HWY 930 OLD STEESE HWY EXACT MATCH
             3 930 OLD STEESE HWY 920 OLD STEESE HWY PROBABLE MATCH
             3 930 OLD STEESE HWY 99 COLLEGE RD      NON MATCH
             4 930 OLD STEESE HWY 80 5TH ST          NON MATCH
    

    In Oracle 11 g, you can use REGEXP_COUNT to count the common words in the address1 and address2:

      2    id,
      3    address1,
      4    address2,
      5    CASE
      6      WHEN address1=address2 THEN 'EXACT MATCH'
      7      WHEN REGEXP_LIKE(address1,'(^| )'||replace(address2,' ','|')||'($| )') THEN 'PROBABLE MATCH'
      8      ELSE 'NON MATCH'
      9    END AS TEST,
     10    regexp_count(address1,'(^| )'||replace(address2,' ','|')||'($| )') common_words
     11  FROM
     12    (
     13    SELECT
     14      1 ID, '930 OLD STEESE HWY' address1, '930 OLD STEESE HWY' address2
     15    FROM
     16      DUAL
     17    UNION SELECT
     18      3 ID, '930 OLD STEESE HWY' address1, '920 OLD STEESE HWY' address2
     19    FROM
     20      DUAL
     21    UNION SELECT
     22      3 ID, '930 OLD STEESE HWY' address1, '99 COLLEGE RD' address2
     23    FROM
     24      DUAL
     25    UNION SELECT
     26      4 ID, '930 OLD STEESE HWY' address1, '80 5TH ST' address2
     27    FROM
     28      DUAL
     29    );
    
            ID ADDRESS1           ADDRESS2           TEST           COMMON_WORDS
    ---------- ------------------ ------------------ -------------- ------------
             1 930 OLD STEESE HWY 930 OLD STEESE HWY EXACT MATCH               4
             3 930 OLD STEESE HWY 920 OLD STEESE HWY PROBABLE MATCH            3
             3 930 OLD STEESE HWY 99 COLLEGE RD      NON MATCH                 0
             4 930 OLD STEESE HWY 80 5TH ST          NON MATCH                 0
    

    Max
    [My Italian blog Oracle | http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/]

    Published by: Massimo Ruocchio on December 29, 2009 22:48
    Added example Regexp_count.

  • Confused about the new iPhone to load

    It seems that online, there are many variations on how to charge an iPhone the first times, we don't know what to believe.

    Historically, I charge my iPhone for a day the first time that I get it or after I got a refurb from Apple. My battery life has always been fantastic, representatives of engineering apply even told to say.

    This time, I couldn't wait to load the device as I normally would. I connected my iPhone to my PC, did a restore of backup and wait for the iPhone to be able to load completely (about 30 minutes).

    Given that I had a lot of things happens, I didn't have the opportunity to "condition" of the battery, charge of the day to the next, or as some reports say that I have to load it only via the provided OEM charger (not PC). Some say that your battery die completely and then get away after the phone two hours before recharging.

    All these 'new' information is downright confusing. And yet, I see Apple suggesting as a result a large part of these 'tips '.

    Any thoughts on pricing?

    There is no requirement to 'manage' load.

    Charge at any time, for any period of time.

    You can use the phone while charging.

    Don't deplete the battery at a low level.

    Another that these steps, no more measures need to be taken.

  • How can I register now. new page is confusing and new

    How can I register the new homepage? everything is new and confused! Or how to make the old version?

    can't give you a print screen. the homepage is back of origin available because he has been and is currently showing. only came for 2-3 days if this. did not keep track of the visual output. Thanks for the reply.

  • iCloud-storage upgrade confusion

    I had a confusion about the upgrade of storage iCloud.

    I want to improve my iCloud storage but it says I have to pay each month. Does this mean that my iCloud storage will continue to increase every month?

    Please help me.

    Thank you.

    NO it does not increase each month, there is a subscription, its like a rent.

  • Help! How to downgrade to 40 of Firefox? I need easy steps. I am very confused.

    I tried to downgrade to Firefox 40 41 is disable my important modules. I need to get instructions. I'm so confused. Please help me.

    If your Firefox 41 said that an extension is disabled because it is not signed or verified, there is a parameter so that it can run anyway. Maybe it's not the problem you are having, but I give the info to the case where.

    (1) in a new tab, type or paste Subject: config in the address bar and press enter/return. Click on the button promising to be careful.

    (2) in the search above the list box, type or paste the xpi and make a pause so that the list is filtered

    (3) if the preference xpinstall.signatures.required is in bold and "user set" true, double-click on it to set it to false

  • Confused.  Try to understand the Photo app Syncing iCloud

    Hi, just bought myself an old 5s iPhone which is big for me.

    I have some questions on how the Photos sync app works on my Mac.  I have a Mac mini desktop computer.

    This sharing of photos is incredible, but I am very new to it and get confused what is actually happening.

    I activated the option "Upload automatically to iCloud" on my iPhone but when I look on my desktop Mac that I do not see my most recent photos appear in the folder called 'iPhone' in my desktop version of Photos.  To get my downloaded photos I must actively download them from my phone.

    This folder has appeared after I connected my iPhone to my Mac via the USB cable.  I did this because someone on Facebook said.  This iTunes open for some reason and other things started happening that I don't understand.  I wanted to share pictures, not tunes and he tried to update but the Wi - fi wasn't working at the time so he kept failing.  When I checked the Wi - Fi works on my phone, it updated but iTunes kept trying to update.  Then the iPhone suddenly had all the records that I had done in Photos on my Mac, but the records were all empty.  Yet, all the Photos I had taken on my iPhone that day appeared on my Mac.  Now finally some pictures randomly my Mac on my iPhone as well and I do not understand why.  Then, when I open Facebook on my iPhone, the pictures that I had taken to a family visit appeared there with a musical slideshow!  What is everything?

    How does this work?  It works by sending photos of the invisible iCloud, which means that it requires action by me to make them appear in my desktop?  In this case, this mean I'll have hundreds, maybe thousands of images are circulating in the iCloud I can forget and end up running out of space on my iCloud?  Or do they stay on my phone until I have actively download them on my Mac?  If I turn off the automatic function, will I still be able to send photos to my Mac?

    If I delete a photo on my Mac, it will also disappear from my iPhone (and vice versa)?

    I have a lot of other questions but my poor old brain melting now and I forgot what I was going to ask, so I'll post them later.

    Thank you for your patience.  I'm old (and a bit thick).

    The IVous article explains works iCloud photo library.

    Photfos user / help guide:

    https://help.Apple.com/photos/Mac/1.0/?lang=en

    IVous has a very detailed and well illustrated article on iCloud photo library:

    http://www.IMore.com/how-use-icloud-photo-library-ultimate-guide

  • I just got an iphone and am confused with itunes.  I the have not used in years.  I can I sync my music from itunes to iphone.

    I just got an iphone and am confused with itunes.  I the have not used in years.  I can I sync my music from itunes to iPhone.

    You need a computer that is running the latest iTunes version to either a Mac or Windows operating system.

    Mac

    1. Open iTunes.
    2. In the MenuBar at the top of your computer screen, choose iTunes > check for the updates.
    3. Follow the prompts to install the latest version.

    Windows

    1. Open iTunes.
    2. In the MenuBar at the top of the iTunes window, choose Help > check for updates. Learn what to do If you see not the menu bar.
    3. Follow the prompts to install the latest version.

    Instructions for syncing your iPhone here > synchronize your iPhone, iPad or iPod touch with iTunes on your computer via a USB - Apple Support

  • Confused. I thought that Firefox for iPad is out? I thought I downloaded but it can not find anywhere. If it's on iPad I want to install it now!

    I'm confused as to whether Firefox is now on iPad too. I can't find. I think it's downloaded?... If I want to uninstall now!

    This isn't Mozilla because it's a fake or a shell. The only thing that Mozilla had on itunes is the application Firefox Home as shown.

    Mozilla probably would have made a mobile version of Firefox for iOS for awhile now, if not for the Apple restrictions on what browser and JavaScript engines can be used.

    Mozilla was really a browser experience for iPad in June 2012, called Junior but of course, it does not use the familiar Gecko engine and say of JavaScript engine used by Firefox. From this moment on, is when some websites started popping up who claims to have a version for iPad, however.

    Also https://support.mozilla.org/en-US/kb/is-firefox-available-iphone-or-ipad

  • I created a photo album that contains 60 photos.  Looking at this album in FCPX there are only 30 pictures inside.  First time this has happened... confused...

    I created a photo album that contains 60 photos.  Looking at this album in FCPX there are only 30 pictures inside.  First time this has happened... confused...

    Using iCloud library in Phoyos? If you're perhaps all the photos in your album have not been downloaded in high resolution.

  • iCloud Confusion

    Hello. I jusy bought an iPad Mini4 and I'm a bit confused about the use of I clouds.

    I have about 2000 images that show now in my Mac Mini (Photos) and my iPad.

    Where these images are actually? I want to keep them on my Mac Mini, but I don't want to clutter up my iPad. Is there a way to remove my iPad and not from my Mac Mini? Sorry for the modo =, thank you.

    MZ

    Learn about iCloud photo library:

    Keep your photos safely stored and updated on all your devices - Apple Support

  • 2 versions of thunderbird listed in my installed programs 17.0.4 and 17.0.5, when I open 'about' it shows that I am running verision 24.6.0. I'm confused

    In the control panel my computer windows 7 tells me that I 17.0.5 and installed two thunderbird 17.0.4
    in respect of aid 'about tuberculosis', he says I'm under 24.6.0 and I'm updating.
    I'm confused. Tried to uninstall the 17.0.4 program and then tuberculosis would not work.
    had to use windows restore get TB works again

    Any help would be appreciated.

    Ignore what version of windows is installed. He remembers what you * first * installed. But thunderbird updates replace the contents of the folder programs and windows is unclear on this issue.

  • synchronization picture confusion

    I returned from vacation and, of course, has taken a lot of pictures.

    I have pictures of iCloud enabled on my iPhone and iPad and the photos are synchronized on both devices. I also have pictures of iCloud enabled on my computer.

    My confusion is with Photos and iPhotos on my computer.

    My understanding is that the replaced pictures iPhotos on Capitan (and earlier versions). If that's true, I don't understand why all my pictures from my iPhone holiday in iPhotos but not appear in the Photos on my computer.

    Can anyone clear this up for me?

    Thank you.

    Please start by telling us your 'My Photo Stream' and "iCloud library" settings on all of your devices. (Settings > Photos & camera on your device iOS and Photos > Preferences > iCloud on your Mac)

Maybe you are looking for

  • Time Machine NAS RAID

    Goal: large, reliable Time Machine back-up. (No purpose: archiving.) I do that separately on optical carriers per year, double copies, which goes off site. I understand that optical media can degenerate over time - even if some are marketed as "of ar

  • IPod will not sync with ITunes

    Windows 10 recognizes that the IPod is docked just like ITunes.  But when you try to sync I have the following message "an IPod has been detected, but it could not be identified properly.  Please disconnect and reconnect the Ipod and then try again. 

  • No popup to close FireFox

    Since I updated to FF 5.0 and now FF 6.0 yesterday, I get yet the pop up notice/warming "you are about to close several tabs you want?" I've had this setting for a few years now, I think. Probably because it was offered. I looked at this article on t

  • How to find the email address of my printer for my printer HP 4622? cc = us

    I can air print from my ipad with airprint on my printer HP 4622 but do not know the e-mail address of printers to send the mail from other places.

  • I have a code 10 error when I insert my SD card. How can I fix it?

    I have a code 10 error when I insert my SD card.  I click on update driver, to connect to windows update, but it cannot complete.  Is there any solution for this?  I reinstalled windows a few months ago SD card worked fine until a few days ago.  Than