oracle中用正则表达式自定义约束总是不对,大虾帮看下哪里错了。。

create table a
(
sdf char (32),
Id char(40),
primary key (sdf),
check (Id like'([0-9]{15})|([0-9]{18})')
);
insert into A values('23','532924199000310143');
最新回答
嘟嘟嘴︶

2025-03-30 14:07:27

Release 10.2.0.1.0

SQL> create table a( sdf char (32),id varchar2(40),
2 primary key (sdf),
3 check (regexp_like(id,'^[0-9]{15,18}')));

Table created.
SQL> insert into A values('23','53292419900031014a');
insert into A values('23','53292419900031014a')
*
ERROR at line 1:
ORA-02290: check constraint (SYS.SYS_C00251603) violated

SQL> insert into A values('23','53292419900031a');
insert into A values('23','53292419900031a')
*
ERROR at line 1:
ORA-02290: check constraint (SYS.SYS_C00251603) violated

SQL> insert into A values('23','532924199000310143');
1 row created.
SQL> insert into A values('22','532924199000310');
1 row created.
SQL> commit;
Commit complete.