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!

MODIFYING Default value of column with ALTER statement.

vugarNov 15 2016 — edited Nov 17 2016

Dear Oracle Users

I have encountered with a tiny problem that needs your attention. I now it is a simple issue but it is important for me. I created a new table called employees_copy by copying first_name and commission_pct rows from employees table. I want to set DEFAULT value (0.5) for COMMISSION_PCT by altering table .I did it but when I insert new rows which included NULL values of COMMISSION_PCT and run select query I see that new row come with NULL value instead of 0.5. I have read that default value works only for new inserts but what is the problem now .I would appreciate if you help me.

create table employees_copy AS select first_name,commission_pct from employees;

update employees_copy set COMMISSION_PCT=NULL; // For Resetting COMMISSION_PCT with NULL values in order to set Default value

alter table employees_copy MODIFY ( COMMISSION_PCT DEFAULT '0.5' );

insert into employees_copy values ('TOM',NULL);

select * from employees_copy; //Please see picture for result. As you see now Default value took into effect.

Capture.PNG

This post has been answered by sdstuber on Nov 15 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2016
Added on Nov 15 2016
6 comments
4,728 views