是否有数据库引擎允许RegEx指定的可查询字段约束? [英] Is There A Database Engine that Allows for Queriable Field Constraint Specified by RegEx?

查看:197
本文介绍了是否有数据库引擎允许RegEx指定的可查询字段约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个数据库引擎,可以处理通过RegEx指定的数据约束。所以除了数据类型,我想要能够控制数据的格式。例如。 varchar(255)字段可以进一步限制为 [a-zA-Z0-9]

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 ].

我需要RegEx能够被查询,所以我可以在n层系统中共享这些约束,以在多个级别上执行。例如。 MySQL允许查询 information_schema 以获取元数据,其他数据库引擎也有类似的方法。

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.

RegEx的MySQL可查询字段约束),引用了我阅读的内容,但是对于MySQL看起来并不乐观,所以我打开这个到任何数据库引擎,虽然我更喜欢MS SQL,Oracle,DB2或MySQL,因为它会更容易销售业务。

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?

推荐答案

在Oracle中,您可以指定自定义约束,您可以在其中使用评估 regexp ;例如:

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

您可以获得有关

select *
from dba_constraints       
where table_name = 'TEST_PATTERN'

这篇关于是否有数据库引擎允许RegEx指定的可查询字段约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆