简体   繁体   中英

Oracle SQL Developer regex expression error

In the script file, I inserted the following code.

drop table Test;
create table Test(
name char(2) unique not null,
constraint name_c check(
regexp_like(name, '^[A-Z]{1,2}$', 'c')
)
);

insert into Test values ('B');

The developer never budge. It keeps on saying violating the name_c constraint and I don't understand why. The regular expression looks fine for me.

Some variants, however, succeeded, for example, dropping the dollar sign

drop table Test;
create table Test(
name char(2) unique not null,
constraint name_c check(
regexp_like(name, '^[A-Z]{1,2}', 'c')
)
);

insert into Test values ('B');

And I don't understand either.

Why?

Edit: This is the problem: logically the regex is right. But somehow Oracle SQL Developer doesn't budge.

在此处输入图片说明

如果您以 1 或 2 个大写字母开头,并且接下来的内容无关紧要,您应该这样做:

^[A-Z]{1,2}.*
.* mean 1 or more character exept \n (nex line)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM