I was tasked to implement a table with a variable groupcode. There are several requirements.
- char(5)
- 2 or 4 uppercase letters plus 1 digit whose value is between 1 and 4 (e.g., AA1, AABB1)
- Any input other violating point 1 and 2 should be banned
The only thing I can come up with is regexp_like but my efforts are in vain, for example
create table Test(
groupcode char(5) check(
regexp_like(groupcode, '^[A-Z]{2}[0-9]$', 'c')
)
);
INSERT INTO Test(groupcode) VALUES ('AA1');
I inserted this but it keep telling me there's some violation, in which I don't understand.
I specify ^
and $
because I don't want something like 'bbAA1'
or 'AA1bb'
appear.
I am also open to non-regex solution. After all the work in this afternoon, I am starting to doubt my approach.