Check Constraints [message #220137] |
Mon, 19 February 2007 01:40 |
|
Hi All,
I want to create a table on insert null(explicitly) should take a specified value, and dont want to use triggers.
like
Insert into tablename values (1,null);
null should be converted to 'TEST'
I am defining table following Implemented using check constraint.
create table aa1
(
n number(1),
name varchar2(10) check (name=decode(name, null, 'TEST'))
);
Table created
SQL> insert into aa1 values (1,null);
1 row created.
SQL> select * from aa1;
N NAME
---------- ----------
1
insert is also successful, but
select * from table; Wont converts the Name to TEST.
Tried nvl also on place of decode.
create table aa1
(
n number(1),
name varchar2(10) check (name=nvl(name, 'TEST'))
);
Table created.
SQL> insert into aa1 values (1,null);
1 row created.
SQL> select * from aa1;
N NAME
---------- ----------
1
Is there any other way without using trigger to do it.
Thank you
|
|
|
Re: Check Constraints [message #220142 is a reply to message #220137] |
Mon, 19 February 2007 01:52 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
A check constraint is just that: a constraint that checks a certain condition, not change a value.
To change an explicitly issued value, there is no other way then using a trigger.
(being bold in this, risking being gazumphed again)
The thing that comes closest to what you want is to define a default value and NOT issue the value null.
|
|
|
Re: Check Constraints [message #220143 is a reply to message #220142] |
Mon, 19 February 2007 02:39 |
|
Thanxs Frank ,
Actually application front end is java hibernate...
And There is condition they have to include this kind of column for further usage. I have already set the value default but they were demanding to do without trigger and also they will provide null in the insert query for the column.
regards
Amit
[Updated on: Mon, 19 February 2007 02:40] Report message to a moderator
|
|
|
Re: Check Constraints [message #220151 is a reply to message #220143] |
Mon, 19 February 2007 03:45 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
Out of curiosity, what difference does it make to the Java team HOW you do it, as long as their requirements are met?
|
|
|
Re: Check Constraints [message #220157 is a reply to message #220151] |
Mon, 19 February 2007 04:37 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
I totally agree with JRowbottom.
Make a deal with the Java team: you do what you do best and they do what they do best. Both of you don't interfere with the other's business by restricting things you do not understand.
|
|
|
|
|
|
Re: Check Constraints [message #221138 is a reply to message #220137] |
Sat, 24 February 2007 05:40 |
crisJedi
Messages: 1 Registered: November 2006 Location: Barcelona
|
Junior Member |
|
|
what about trying this:
create or replace trigger aa1_tg
before insert on aa1
for each row
begin
if :new.name is null then
:new.name := 'Test';
end if;
end;
/
best regards,
cris..
|
|
|
Re: Check Constraints [message #221143 is a reply to message #220137] |
Sat, 24 February 2007 06:25 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
amit_nanote wrote on Mon, 19 February 2007 08:40 | Is there any other way without using trigger to do it.
|
crisJedi wrote: | what about trying this:
create or replace trigger aa1_tg
before insert on aa1
|
|
|
|
|
|