Home » SQL & PL/SQL » SQL & PL/SQL » problem in table creation (oracle 11g, 11.2, xp)
problem in table creation [message #569028] Thu, 18 October 2012 15:29 Go to next message
maan1789
Messages: 7
Registered: September 2012
Junior Member
i want to create a table to perform a task when i insert client account details in this table then check the
account type is in(S,C,R) and
balance should be also check when account type S then balance >=5000, account type C then balance >=10000 and
account type R then balance >=5000
but when i run this query then facing error "ORA-02438: Column check constraint cannot reference other columns"



SQL> ed
Wrote file afiedt.buf

1 create table kcb_acc_tab
2 (
3 accno varchar2(20) constraint accno_pk primary key,
4 name varchar2(20) constraint name_nn not null
5 constraint name_chk check((substr(name,1,1) between 'A' and 'Z') and name=upper(name)),
6 acctype char constraint acctype_nn not null
7 constraint acctype_chk check(acctype in ('S','C','R')),
8 dot timestamp default sysdate,
9 bal number(7,2) constraint bal_chk check ((acctype='S' and bal>=5000)
10 or (acctype='C' and bal>=10000)
11 or (acctype='R' and bal>=5000))
12* )
SQL> /
)
*
ERROR at line 12:
ORA-02438: Column check constraint cannot reference other columns
Re: problem in table creation [message #569030 is a reply to message #569028] Thu, 18 October 2012 15:32 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
02438, 00000, "Column check constraint cannot reference other columns"
// *Cause: attempted to define a column check constraint that references
//         another column.
// *Action: define it as a table check constriant.


Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: problem in table creation [message #569031 is a reply to message #569030] Thu, 18 October 2012 15:48 Go to previous messageGo to next message
maan1789
Messages: 7
Registered: September 2012
Junior Member
I'm enable to understand how to solve this problem.
Re: problem in table creation [message #569032 is a reply to message #569031] Thu, 18 October 2012 16:02 Go to previous messageGo to next message
John Watson
Messages: 8979
Registered: January 2010
Location: Global Village
Senior Member
The problem is absolutely clear:
ORA-02438: Column check constraint cannot reference other columns
To take a trivial example:
orcl> create table t1(c1 number,c2 number constraint con1 check (c2 > c1));
create table t1(c1 number,c2 number constraint con1 check (c2 > c1))
                                                                   *
ERROR at line 1:
ORA-02438: Column check constraint cannot reference other columns


orcl> create table t1(c1 number,c2 number constraint con1 check (c2 > 10));

Table created.


orcl>

--
Edit: sorry, hit the wrong key. You add the constraint later:
orcl>  create table t1(c1 number,c2 number);

Table created.

orcl> alter table t1 add constraint con1 check (c2 > c1);

Table altered.

orcl>

[Updated on: Thu, 18 October 2012 16:08]

Report message to a moderator

Re: problem in table creation [message #569033 is a reply to message #569032] Thu, 18 October 2012 16:34 Go to previous message
maan1789
Messages: 7
Registered: September 2012
Junior Member
problem solve thank you sir
Previous Topic: ORA-29278: SMTP transient error: 401 4.1.7 Bad sender address syntax
Next Topic: How to get minutes between two times?
Goto Forum:
  


Current Time: Fri Jul 25 09:15:55 CDT 2025