Friday, September 27, 2013

How to limit a column in oracle to support only character


The below example shows test_name column can't take NUMBER values.


CREATE TABLE test_1
(
  test_id number,
  test_name varchar(50),
  CONSTRAINT
    name_test
    CHECK (
      regexp_like(test_name,'^([aA-zZ])+$')
    )
);

Table created.


SQL> insert into test_1 (test_id,test_name) values (200,'Akash')
  2  /

1 row created.

SQL> insert into test_1 (test_id,test_name) values (200,'Akash1');
insert into test_1 (test_id,test_name) values (200,'Akash1')
*
ERROR at line 1:
ORA-02290: check constraint (SCOTT.NAME_TEST) violated


--------------------------------------------****************************--------------------------



Secondly, If we want to change all the column values to UPPER-CASE ,  this can be done as follows.

SQL> select * from test_1;

   TEST_ID TEST_NAME
---------- ------------------------------------------------
       200 Akash

SQL> UPDATE test_1
  2  set    test_name= upper(test_name);

1 row updated.

SQL> commit;

Commit complete.

SQL> select * from test_1;

   TEST_ID TEST_NAME
---------- ------------------------------------------------
       200 AKASH





No comments:

Post a Comment