Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

conditional default value

WestDraytonJul 6 2010 — edited Jul 6 2010
I have table "Players" like this:
with Players as
(select 1 Code, 0 Flag1, null Newfield from Dual
union
select 2 Code, 1 Flag1, null Newfield from Dual
union
select 3 Code, 1 Flag1, 5 Newfield from Dual
)
select * from Players
/*
1	1	0	
2	2	1	
3	3	1	5

*/
;
I want to achieve following needs:
1. If "Players.flag1"=1 then Default value to column Newfield must be "4".
2. If "Players.flag1"<>1 then Default value to column Newfield doesn't exist, it can be even empty, anything.
3. Triggers are not allowed to use because Database Architect doesn't allow them.

How can i achieve such conditional Default value to be put to the table?

Note that this code is not correct:
ALTER TABLE Players MODIFY NewField DEFAULT 4;
Because it always sests default value to the NewField, which is not correct. We want default value only when "flag1"=1.

Seems like we are not allowed to use such grammar:
ALTER TABLE Players MODIFY NewField DEFAULT 4 when flag1=1;
or
ALTER TABLE Players MODIFY NewField DEFAULT decode(flag1, 1, 4, null);
This post has been answered by Karthick2003 on Jul 6 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 3 2010
Added on Jul 6 2010
4 comments
2,155 views