0

I am using oracle XE and trying to add a attribute that restricts to only three available value 'Small','Medium','large' to an existing table using Alter Table and Enum.

Tried doing,

ALTER TABLE TRUCK ADD TTYPE ENUM('SMALL','MEDIUM','LARGE');

but gets invalid option

ALTER TABLE TRUCK ADD TTYPE ENUM('SMALL','MEDIUM','LARGE');
                                 *

where the error highlights after ENUM.

I think I am having syntax error. Please help to resolve.

1

I think you want this:

ALTER TABLE TRUCK 
    ADD (ttype VARCHAR2(6) 
    CONSTRAINT con_type 
    CHECK (ttype in('SMALL','MEDIUM','LARGE'))
    );
0

There is no ENUM datatype in Oracle. You can use a foreign key constraint to a reference table (with 3 rows) or a CHECK constraint instead:

ALTER TABLE truck 
  ADD ttype VARCHAR(6),
  ADD CONSTRAINT ttype_check
    CHECK (ttype IN ('SMALL','MEDIUM','LARGE')) ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.