Home » RDBMS Server » Server Administration » how do you set a fixed character length
how do you set a fixed character length [message #372416] Fri, 09 February 2001 14:28 Go to next message
Zufar
Messages: 2
Registered: February 2001
Junior Member
I want to set it so that the user has to type 3 characters for deptcode, unable to type in 1 or 2 characters for deptcode. Any help would be appreciated.

create table dept (
deptcode CHAR(3) NOT NULL,
deptname VARCHAR2(20)
);
Re: how do you set a fixed character length [message #372423 is a reply to message #372416] Mon, 12 February 2001 03:43 Go to previous message
Balazs VISSY
Messages: 17
Registered: January 2001
Junior Member
Use constraint:

create table dept (
deptcode CHAR(3) NOT NULL
CHECK (length(depcode)=3),
deptname VARCHAR2(20)
);

or after the table was created:

alter table dept
add constraint ck_dept_length check (length(depcode)=3);

It raises an error when a DML line tries fails the criterium.

However, if you would like to check it when entered (client side), you have to look for the answer in the developing tool documentation.

Balage
Previous Topic: SQL
Next Topic: What is the Query?
Goto Forum:
  


Current Time: Sat Jun 01 22:28:45 CDT 2024