nostress nostress -4 years ago 118
SQL Question

Oracle: How to add constraint to only allow a particular set of numbers in a string column

I have a string column, which stores numbers. How can I add a constraint to make sure that the number consists of only

6
or
7
. Example
676666
But I do not want
565677

Answer Source

Add a check constraint:

CONSTRAINT check_numbers CHECK (regexp_like(the_column, '^[67]+$')) 

This requires at last one digit.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download