We're learning about databases and for our case the database is Oracle, in class we we're asked to create a constraint based on the information of another field on the table, and the constraint should be build with a case inside, despite of a large google search nothing worked for me (we're working on apex Oracle online platform), so here is what we were asked to do:
Based on the acumuladoCompra
field and Clasification
field do the following:
If the classification is A the acumuladocompra
must be less than $20,000; if the classification is E the acumuladocompra
should be between $20,001 and $40,000; if the classification is I, the acumuladocompra
must be greater than $40,001 but less than $60,000; if the classification is O the acumuladocompra
must be less than $80,000 but more than $60,001; otherwise it should be higher to $100,000
So, how could this be build?
Edit: I've tried this code:
alter table "CLIENTES_152" add constraint "RESTRICCIONCLASIFICA" check ( CASE when CLASIFICACION_152 = A THEN ACUMULADOCOMPRA_152 <20000;
when CLASIFICACION_152 = E THEN ACUMULADOCOMPRA_152 BETWEEN 20001 AND 40000;
when CLASIFICACION_152 = I THEN ACUMULADOCOMPRA_152 >40001 AND <60000;
when CLASIFICACION_152 = O THEN ACUMULADOCOMPRA_152 >60001 AND <80000;
when CLASIFICACION_152 = U THEN ACUMULADOCOMPRA_152 >100000; END)
But got
ORA-00905: missing keyword
What's wrong?