简体   繁体   中英

Oracle Constraint Letters Only SQL REGEXP

I already have my tables full of data, I am trying to add a constraint to only allow letters to be entered into the attribute I have named as studentfname. I have tried various different REGEXP but cannot seem to get any to work without getting an error when inserting them.

Im not sure if its a syntax error or what!

Edit: Here is what I have tried and the error I am getting:

ALTER TABLE STUDENT
ADD CONSTRAINT
check_name
 CHECK(regexp_like(studentfname,'^[A-Za-z''-]+$'));

Error:

QL Error: ORA-02293: cannot validate (JEIGH7.CHECK_NAME) - check constraint violated
02293. 00000 - "cannot validate (%s.%s) - check constraint violated"
*Cause:    an alter table operation tried to validate a check constraint to
           populated table that had nocomplying values.
*Action:   Obvious

Apparently you can try to run this below query to check if any non integral data resides in the above mentioned column which is preventing you from applying a check constraints. Once you get the output from this query try UPDATING/DELETING the row and then apply the constraint. Hope this helps.

SELECT studentfname nm FROM STUDENT a
WHERE NOT regexp_like(a.nm,'^[A-Za-z''-]+$');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM