Home » RDBMS Server » Server Administration » getting there
getting there [message #374330] Wed, 06 June 2001 09:02 Go to next message
LEVIATHAN
Messages: 8
Registered: June 2001
Junior Member
I want to restict data entry so that of the 6 characters allowed, the first three characters can only be numbers (1 to 9) and the last three can
only be letter (A TO Z). Below is a sample of what I have done. But I dont understand why it wont accept my inserted values.

create table subject
(subject_id varchar2(6) not null constaint subject_pk primary key etct...

ALTER TABLE SUBJECT
ADD CONSTRAINT CHK_SUBJECT_ID CHECK
(SUBSTR(SUBJECT_ID, 1,1)<='9' AND
SUBSTR(SUBJECT_ID, 1,1)>='0' AND
SUBSTR(SUBJECT_ID, 2,1)<='9' AND
SUBSTR(SUBJECT_ID, 2,1)>='0' AND
SUBSTR(SUBJECT_ID, 3,1)<='9' AND
SUBSTR(SUBJECT_ID, 3,1)>='0' AND
SUBSTR(SUBJECT_ID, LENGTH(SUBJECT_ID) -1,1)<='Z' and
SUBSTR(SUBJECT_ID, LENGTH(SUBJECT_ID) -1,1)>='A' and
SUBSTR(SUBJECT_ID, LENGTH(SUBJECT_ID) -2,1)<='Z' and
SUBSTR(SUBJECT_ID, LENGTH(SUBJECT_ID) -2,1)>='A' and
SUBSTR(SUBJECT_ID, LENGTH(SUBJECT_ID) -3,1)<='Z' and
SUBSTR(SUBJECT_ID, LENGTH(SUBJECT_ID) -3,1)>='A');

insert into subject values ('999ZED');
BUT I get message check contraint violated why?
Re: getting there [message #374354 is a reply to message #374330] Thu, 07 June 2001 08:45 Go to previous message
Lars Sjöström
Messages: 24
Registered: June 2001
Junior Member
COuld be so that your existing data does not meet the requirements stated in that very constraint.
Previous Topic: select largest tables with variables
Next Topic: upper
Goto Forum:
  


Current Time: Mon Jul 01 03:41:39 CDT 2024