-2

Column should follow below validation needs to be implemented with constraints in oracle db

  1. Should Be Only in Upper Case
  2. Should Not Contain Leading and Trailing Spaces
  3. Should Not Contain Extra Spaces Other Than One Space Between The Words
  4. Should Not Contain Special Characters and Numbers Anywhere in The Text
4
  • Column data should follow the above mentioned constraints Commented Aug 28, 2020 at 19:57
  • 2
    Give it a try. If you run into problems you can ask a specific question here. Commented Aug 28, 2020 at 19:59
  • stackoverflow.com/questions/7621568/… Commented Aug 28, 2020 at 20:02
  • I’m voting to close this question because it contains no effort, seems like dumped homework. Commented Aug 29, 2020 at 11:53

1 Answer 1

1

See if this helps.

SQL> create table test
  2    (col  varchar2(20),
  3     --
  4     constraint ch1_upper check (col = upper(col)),
  5     --
  6     constraint ch2_letraspc check (col = trim(col)),
  7     --
  8     constraint ch3_wrdspc check (regexp_like(col, '^ *(\w+ ?)+ *$')),
  9     --
 10     constraint ch4_spec check (regexp_like(col, '^[[:alpha:] ]+$'))
 11    );

Table created.

Testing:

SQL> insert into test values ('abc');
insert into test values ('abc')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH1_UPPER) violated


SQL> insert into test values (' DEF');
insert into test values (' DEF')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH2_LETRASPC) violated


SQL> insert into test values ('DEF ');
insert into test values ('DEF ')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH2_LETRASPC) violated


SQL> insert into test values (' DEF ');
insert into test values (' DEF ')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH2_LETRASPC) violated


SQL> insert into test values ('GHI23');
insert into test values ('GHI23')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH4_SPEC) violated


SQL> insert into test values ('GHI#');
insert into test values ('GHI#')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH4_SPEC) violated


SQL> insert into test values ('GHI   JKL');
insert into test values ('GHI   JKL')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH3_WRDSPC) violated


SQL> insert into test values ('GHI JKL    MNO');
insert into test values ('GHI JKL    MNO')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.CH3_WRDSPC) violated


SQL> insert into test values ('GHI JKL MNO');

1 row created.

SQL>
Sign up to request clarification or add additional context in comments.

1 Comment

I want do this without regex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.