Create table with a REGEXP_LIKE Constraint
CREATE TABLE regexp_temp(Name varchar2(20), emailID varchar2(20) CONSTRAINT mailchck CHECK (REGEXP_LIKE (emailID, '^(\S+)\@(\S+)\.(\S+)$')))
Table created.
Insert a valid row
INSERT INTO regexp_temp (Name, emailID) VALUES ('abcd', 'abcd@email.com')
1 row(s) inserted.
Select the inserted information for display
SELECT emailID FROM regexp_temp WHERE REGEXP_LIKE(emailID, '^(\S+)\@(\S+)\.(\S+)$')
EMAILID | abcd@email.com |
---|
DROP TABLE regexp_temp
Table dropped.
Create a table without a constraint clause
CREATE TABLE regexp_temp(Name varchar2(20), emailID varchar2(20))
Table created.
INSERT INTO regexp_temp (Name, emailID) VALUES ('efgh', 'efghemail.com')
1 row(s) inserted.
INSERT INTO regexp_temp (Name, emailID) VALUES ('ijkl', 'efghijkl.com')
1 row(s) inserted.
INSERT INTO regexp_temp (Name, emailID) VALUES ('mnop', 'mnop@email.com')
1 row(s) inserted.
INSERT INTO regexp_temp (Name, emailID) VALUES ('wxyz', 'wxyz@email.com')
1 row(s) inserted.
Querty the table with REGEXP_LIKE
SELECT emailID "VALID EMAILS" FROM regexp_temp WHERE REGEXP_LIKE(emailID, '^(\S+)\@(\S+)\.(\S+)$')
VALID EMAILS | mnop@email.com | wxyz@email.com |
---|
Query the table for non-matching email IDs
SELECT emailID "INVALID EMAILS" FROM regexp_temp WHERE emailID NOT LIKE '%_@_%'
INVALID EMAILS | efghemail.com | efghijkl.com |
---|
DROP TABLE regexp_temp
Table dropped.