-2

I have a table,

create table a(
id_a number(5) not null, 
name varchar2(15) not null, 
address varchar2(30), 
phone varchar2(15), 
constraint pk_a primary key (id_a)
);

I want add constraint check at phone. example. phone is 08175210868

I want to only be input with +628175210868

sorry my bad english.

newbie
  • 41
  • 1
  • 1
  • 6
  • Please check [this](http://stackoverflow.com/questions/10606552/check-for-character-format-in-oracle) thread for possible solutions. Also you could already gave a try searching SO for possible answers. – kayess Jun 15 '15 at 10:04
  • I guess you have a typo, both the numbers are completely different. `752` or `725`? – Lalit Kumar B Jun 15 '15 at 10:13

2 Answers2

0

Try to add a row-level trigger

CREATE OR REPLACE TRIGGER VALIDATE_PHONE 
BEFORE INSERT OR UPDATE OF PHONE ON A 
REFERENCING OLD AS OLD NEW AS NEW 
FOR EACH ROW 
DECLARE
    ex_phone       EXCEPTION;
BEGIN
  IF :NEW.PHONE not like '+62%' THEN raise ex_phone; END IF;
END;
Damsen
  • 31
  • 3
-1

You can try the below

alter table b add constraint phone check (phone like '+62%');
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Siby
  • 1