-1

I am facing issue adding constraint to the column of table in oracle- The column is defined with the datatype char(500 char). I need to put the constraint which allows only the digits and N/A value to be inserted in the column.

1
  • Please edit the question with, what you tried and the issue that you are facing Commented Feb 10, 2016 at 7:59

2 Answers 2

1

From this article stack overflow article: Oracle 11g - Check constraint with RegEx you can see that regex works on check constraints.

A regex which supports what you want would be:

^([0-9]+|N/A)$

^ at start of expression means start of line/row/text; [0-9]+ digits 1 to x; | or operator; N/A a specific text; $ end of line/row/text

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks ... But this regex is allowing me to insert other charaters as well :(
I got a problem testing it right now. But i guess i missed the boundaries from where to where the string has to be found. I'll update my answer.
0

You can try like this:

 CHECK (column IN (REGEXP_LIKE(column, '^[[:digit:]]{9}$'), 'N/A')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.