使用正则表达式^( +|[A-Z '.-]*[A-Z][A-Z '.-]*)$
匹配仅由以下任一组成的字符串:
+
所有空格字符;或者
[A-Z '.-]*[A-Z][A-Z '.-]*
零个或多个字母或特殊字符,然后是一个字母字符,然后是零个或多个字母或特殊字符。
像这样:
甲骨文设置:
CREATE TABLE data (
value VARCHAR2(100),
CONSTRAINT value__alpha_or_special_chr CHECK ( REGEXP_LIKE( value, '^( +|[A-Z ''.-]*[A-Z][A-Z ''.-]*)$' ) )
);
插入有效数据:
INSERT INTO data ( value )
SELECT q'!ORACLE!' FROM DUAL UNION ALL
SELECT q'!ORA..C L--E!' FROM DUAL UNION ALL
SELECT q'!'''..O!' FROM DUAL UNION ALL
SELECT q'!O--...''''!' FROM DUAL UNION ALL
SELECT q'! !' FROM DUAL
无效数据失败:
INSERT INTO data ( value )
SELECT q'!''''''''''!' FROM DUAL;
ORA-02290: 违反检查约束 (FIDDLE_TRJCYMMSYLSIPALCEYXD.VALUE__ALPHA_OR_SPECIAL_CHR)
INSERT INTO data ( value )
SELECT q'!--------!' FROM DUAL;
ORA-02290: 违反检查约束 (FIDDLE_TRJCYMMSYLSIPALCEYXD.VALUE__ALPHA_OR_SPECIAL_CHR)
INSERT INTO data ( value )
SELECT q'!ORACLE$!' FROM DUAL;
ORA-02290: 违反检查约束 (FIDDLE_TRJCYMMSYLSIPALCEYXD.VALUE__ALPHA_OR_SPECIAL_CHR)
INSERT INTO data ( value )
SELECT q'!ORACL#E!' FROM DUAL;
ORA-02290: 违反检查约束 (FIDDLE_TRJCYMMSYLSIPALCEYXD.VALUE__ALPHA_OR_SPECIAL_CHR)
查询:
SELECT * FROM data;
输出:
| 价值 |
| :----------- |
| 甲骨文 |
| ORA..C L--E |
| '''..O |
| O--...'''' |
| |
db<>在这里摆弄