Search code examples
oracle-databaseoracle11gcheck-constraints

Oracle Database Can set Constraint for Upper Case Values?


Is there anyway that we can set a constraint in database table level to have upper or lower case values for certain columns? When we create a table, we can set NOT NULL to avoid having null values on a column. Same way, can we do that for either uppercase or lower case?


Solution

  • You can do that using a check constraint:

    create table foo
    (
       only_lower varchar(20) not null check (lower(only_lower) = only_lower),
       only_upper varchar(20) not null check (upper(only_upper) = only_upper)
    );