• Post author:
  • Post category:PLSQL / SQL
  • Reading time:2 mins read

Here I am giving an example to validate email address using PL/SQL regular expressions (REGEXP) in Oracle.

Validate Email Using PL/SQL Program

In the following PL/SQL program, it will validate the email address using the REGEXP_LIKE function.

SET SERVEROUTPUT ON;

DECLARE
   b_isvalid   BOOLEAN;
BEGIN
   b_isvalid :=
      REGEXP_LIKE ('anyaddress@xyz123.com',
                   '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$');

   IF b_isvalid
   THEN
      DBMS_OUTPUT.put_line ('It is a valid email address.');
   ELSE
      DBMS_OUTPUT.put_line ('It is Not a valid email address.');
   END IF;
END;
/

Output

It is a valid email address.
PL/SQL procedure successfully completed.

Get the List of Invalid Email Addresses from a Table Using SQL

The following SQL query will retrieve all the invalid email addresses stored in the EMAIL column of EMPLOYEES table in Oracle.

SELECT *
  FROM EMPLOYEES
 WHERE NOT REGEXP_LIKE (email,
                        '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$');

Similarly, to get the list of valid email addresses, delete NOT from the above query.

See also:

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.

This Post Has 6 Comments

  1. Jonas Wegelius

    this does not pass some valid email addresses, example:
    test123@bk.ru

    1. Vinish Kapoor

      Hi Jonas,

      I tested for the email id you mentioned and it is returning the correct result:

      Select
        'Valid'
      From
        dual
      Where
        Regexp_Like ( 'test123@bk.ru',
               '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$' );
      

      The above query returning a row, meaning it is the valid address.

  2. anuj

    can email id start with a dot (.) , this is passing it.

    1. Lokesh

      no ishould check only @ if it is not present in email it should show bounced in another column, and i want full code can you please do it in stored procedure

  3. Lokesh

    Hi I am Lokesh, I have one scenario can solve it and share that in plsql procedure and share to me pplease and expalin things how u solved

  4. Chris

    Can you post an example of using REGEXP_LIKE to validate a URL string?

Comments are closed.