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!

Adding not null column with default value

SaadLiaqatFeb 4 2019 — edited Feb 6 2019

Good Morning,

I got a schema update request from our dev team. They wanted to add a column in one of our tables and some prod DBs have more than 7bill records inside.

My ora version is 11.2.0.4, the compatibility parameter is also set to 11.2.

The column they wanted to add was as follows:

alter table event add (inserted timestamp default sys_extract_utc(systeimstamp) not null);

I tested this on smaller DBs and it ran fine. Then I tried on a bigger table (2 billion records) and it just kept running.

Session showed LOTS of physical reads

my understanding was that with 11.2.0.4, such addition is done directly on data dictionary.  (please correct me if I am wrong).

Anyways, for testing purposes, i modified the above statement and instead of call to function (sys_extract_utc) I put in the timestamp value selecting it from dual so my query became:

alter table event add (inserted timestamp default '04-FEB-19 11:06.11.101700 PM' not null);

This ran in MILLISECONDS.

Now i am trying to figure out why, was this one fast compared to other one ? is it because of the function call ?

does oracle add something extra when we specify a dynamic value like this during column additions ?, maybe I am over-looking something ?

Appreciate the help .

Thanks

Saad

This post has been answered by Hans Steijntjes on Feb 4 2019
Jump to Answer
Comments
Post Details
Added on Feb 4 2019
8 comments
2,041 views