oracle 11g 添加字段default值对历史数据影响

创建测试表

SQL> create table test_default

2 (id number,
3 comm varchar2(10));

Table created

插入测试数据

SQL>
SQL> insert into test_default values (1,'a');

1 row inserted
SQL> insert into test_default values (2,'b');

1 row inserted
SQL> insert into test_default values (3,'c');

1 row inserted

SQL> commit;

Commit complete


查询


SQL> select * from test_default;

ID COMM
---------- ----------
1 a
2 b
3 c

给表添加新的字段,带默认值0,不是not null

SQL> alter table test_default add new_col varchar2(2) default '0';

Table altered


再次查询


SQL> select * from test_default;

ID COMM NEW_COL
---------- ---------- -------
1 a 0
2 b 0
3 c 0

SQL>


结论,oracle11g中给表添加字段带default值会自动更新历史数据。