Reputation: 1
I want to restrict the container id to be letter "E" on a front and then up to 7 digits, ex.: E1234567
.
How can I do that in Oracle sql?
The simplest example: select * from inventory where container_id like ???
Upvotes: 0
Views: 704
Reputation: 521073
If you are looking to modify your query, this would suggest using REGEXP_LIKE
:
SELECT *
FROM inventory
WHERE REGEXP_LIKE (container_id, '^E[0-9]{1,7}$');
If on the other hand you are looking for a way to enforce your pattern for every container ID, then you can try adding a check constraint:
ALTER TABLE inventory
ADD CONSTRAINT check_inv
CHECK (REGEXP_LIKE (container_id, '^E[0-9]{1,7}$'));
Upvotes: 2