Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

REGEXP_LIKE help with literal single-quote

orclrunnerFeb 10 2012 — edited Mar 1 2013
I'm trying to write a check constraint to validate email addresses that may include an apostrophe in the email address. Such as joe.o'malley@navy.mil. Here is my sample setup:
create table emails
( email_address varchar2(150)
)
/

insert into emails values('joe.black.ctr@us.army.mil') ;
insert into emails values('mary.anne.lucas@dfas.mil') ;
insert into emails values('joey.o''halleran@mail.mil') ;

commit;

sql> select * from emails;

EMAIL_ADDRESS
-------------------------------------------------
joe.black.ctr@us.army.mil
mary.anne.lucas@dfas.mil
joey.o'halleran@mail.mil

alter table emails add constraint email_address_format_ck 
    CHECK ( REGEXP_LIKE ( email_address, '^[a-z0-9._%-]\'?+@[a-z0-9._%-]+\.mil$','c'));
    
ERROR at line 2:
ORA-00911: invalid character
It doesn't like *\'?*

My understanding is this means one or more single-quotes. Anyone know the correct syntax to accept apostrophes?
This post has been answered by Frank Kulash on Feb 12 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2013
Added on Feb 10 2012
7 comments
8,157 views