Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

sql server - Is There A Database Engine that Allows for Queriable Field Constraint Specified by RegEx?

I'm looking for a database engine that can handle data constraints specified via RegEx. So in addition to the datatype, I want to be able to control the format of the data. E.g. a varchar(255) field could be further restrained to be like [a-zA-Z0-9 ].

I need the RegEx to be able to be queried too, so I can share those constraints throughout the n-tier system to enforce on several levels. E.g. MySQL allows for querying of information_schema to get meta data, and other database engines have similar ways.

I did a post yesterday (MySQL Queriable Field Constraint by RegEx), referencing things I read, but doesn't look promising with MySQL, so I'm opening this up to any db engine, although I would prefer MS SQL, Oracle, DB2 or MySQL, as it'll be easier to sell the business on.

Is there a database engine out there that allows for these regex restrictions? If so, which one is it and how do the constraints get set and queried?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In Oracle you can specify custom constraints, in which you can use functions that evaluate regexp; for example:

SQL> create table test_pattern ( txt varchar2(1000))
  2  /

Table created.

SQL> alter table test_pattern add constraint check_pattern check (regexp_instr(txt, '^START') != 0)
  2  /

Table altered.

SQL> insert into test_pattern values ('START a d f  g ')
  2  /

1 row created.

SQL> insert into test_pattern values ('_START a d f  g ')
  2  /
insert into test_pattern values ('_START a d f  g ')
*
ERROR at line 1:
ORA-02290: check constraint (SIUINTEGRA.CHECK_PATTERN) violated

You can get informations on constraints you set with something like:

select *
from dba_constraints       
where table_name = 'TEST_PATTERN'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...