Home » PLSQL » How to Validate Email Address Using PL/SQL?

How to Validate Email Address Using PL/SQL?

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:

6 thoughts on “How to Validate Email Address Using PL/SQL?”

    1. 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.

    1. 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

  1. 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

Comments are closed.