I have a field which will contain a number, how can I do complex validation on that number on insertion?
I've got the validation algorithm implemented in java, just wondering how to "translate it" to SQL. Like I do some calculations with the inserted number and if the calculations don't match a predetermined result I want to reject that entry. How do I go about this?
I'm assuming I need to use a Check Constraint on the field, but how do I incorporate my validation algorithm in the constraint?
My algorithm looks like this
int s=0;
for (int i = 0; i < 10; i++)
{
s+=n%10;
n/=10;
}
if(n==s)
//Good Value
Where n
is initially my value to be inserted.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…