to create an trigger in pl/sql
i have a problem that i want to create an trigger t开发者_开发问答hat checks the Pincode number is exactly six of digit or not.
please tell me an detail answer.
I suppose you mean a character column in your question, if so - you can achieve this without trigger but using check constraint like this:
create table test_1
(
pincode varchar2(20)
constraint test_1$chk$id check (ltrim(pincode, '0123456789') is null and length(pincode)= 6)
);
Running these inserts:
insert into test_1 (pincode) values ('45sdgf65');
insert into test_1 (pincode) values ('4565');
Will result the error:
ORA-02290: check constraint (ANDREW.TEST_1$CHK$ID) violated
But this one goes ok:
insert into test_1 (pincode) values ('034565');
精彩评论