Home » SQL & PL/SQL » SQL & PL/SQL » Input controls!!! (constraints)
Input controls!!! (constraints) [message #10108] Mon, 05 January 2004 21:56 Go to next message
P
Messages: 29
Registered: May 2002
Junior Member
Hi,

If someone inserts data in the field 'name', it must be alfanumeric...
how can you do this when you create you're table? (with wich constraint)
Re: Input controls!!! (constraints) [message #10112 is a reply to message #10108] Mon, 05 January 2004 23:59 Go to previous messageGo to next message
Frank Naude
Messages: 4579
Registered: April 1998
Senior Member
Hi,

Look at this example:

SQL> CREATE TABLE tab1 (
  2    name VARCHAR2(30)
  3      CONSTRAINT name_not_alfa CHECK (TRIM(TRANSLATE(name,
  4                 ' 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
  5                 '                                                               '))
  6                 IS NULL)
  7  );
Table created.

SQL>
SQL> INSERT INTO tab1 VALUES ('Alfanumeric value 1 2 3');
1 row created.

SQL> INSERT INTO tab1 VALUES ('Non-Alfanumeric value!');
INSERT INTO tab1 VALUES ('Non-Alfanumeric value!')
*
ERROR at line 1:
ORA-02290: check constraint (HR.NAME_NOT_ALFA) violated


Best regards.

Frank
Re: Input controls!!! (constraints) [message #10117 is a reply to message #10112] Tue, 06 January 2004 00:18 Go to previous message
Pieter
Messages: 6
Registered: August 2002
Junior Member
Thanx!
Previous Topic: non functioning of set pause on command
Next Topic: Stored procedure, what im a doing wrong?
Goto Forum:
  


Current Time: Wed Apr 24 18:01:02 CDT 2024