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 ('[email protected]', '^[A-Za-z0-9._%+-][email protected][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._%+-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$');
Similarly, to get the list of valid email addresses, delete NOT from the above query.