How to delimit a telephone field (Oracle DataBase)

1

Good morning,

I'm looking for a help to delimit the phone field in my database, being more specific, if today someone enter a phone number with 4 digits (for example) that phone will be saved, I need it to be accepted only numbers between 8 and 9 digits, I'm using Oracle 11g.

    
asked by anonymous 17.04.2017 / 17:35

1 answer

1

One solution might be to create a check constraint.

For example

ALTER TABLE  CLIENTES
ADD CONSTRAINT CHK_CLIENTES_TEL
  CHECK (TELEFONE IS NULL OR LENGTH(TRIM(TELEFONE)) IN (8,9));

Here for example you will allow null phone, client has no phone, etc., but if filled in should have size of 8 or 9.

    
17.04.2017 / 20:14