This is a discussion on Constraint to allow all numers and alpha within the Database Support forums, part of the Web Development category; Does anyone know how to develop a check constraint in oracle that will only allow digits 0-9 and a ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Does anyone know how to develop a check constraint in oracle that will only allow digits 0-9 and a dash? Thank you ahead of time.
__________________ H2O Without us, no one can survive.. |
| Sponsored Links |
| |||
| Hi, Refer the details given below.. Quote:
__________________ Keep smiling... |
| |||
| Is there a way to format it like a zip code, for instance the field is zip code, I want to allow either a format like this 99999 or 99999-9999. Is there a constraint that will validate against either format and check for the "-" as well? Please let me know and thank you for your answer!!!
__________________ H2O Without us, no one can survive.. |
| |||
| SQL>CREATE TABLE TEST_TABLE 2 ( 3 number_and_ VARCHAR2(30) 4 CONSTRAINT p_check 5 CHECK ( REGEXP_LIKE ( number_and_, '^[0-9\-]*$' ) ) 6 ) 7 / Table created. SQL>insert into TEST_TABLE values('-'); 1 row created. SQL>insert into TEST_TABLE values('0-9'); 1 row created. SQL>insert into TEST_TABLE values('0-9222-'); 1 row created. SQL>insert into TEST_TABLE values('0-9222-*'); insert into TEST_TABLE values('0-9222-*') * ERROR at line 1: ORA-02290: check constraint (P_CHECK) violated |
| |||
| |
| |||
| > Is there a way to format it like a zip code, for > instance the field is zip code, I want to allow > either a format like this 99999 or 99999-9999. Is > there a constraint that will validate against either > format and check for the "-" as well? > > Please let me know and thank you for your answer!!! create table test (str varchar2(100) constraint t_check check(translate(str,'012345678','999999999') in ('99999','99999-9999'))) |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/database-support/3168-constraint-allow-all-numers-alpha.html | |||
| Posted By | For | Type | Date |
| DiscussWeb IT Community - Technical Support and Technology Discussions | This thread | Refback | 08-20-2007 08:12 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is alpha an beta testing? | devarajan.v | Software Testing | 1 | 07-16-2007 10:52 PM |