我有一个表,其中有15列,proc只填充7列。现在,它被要求在所有其他列中插入NULL。列定义无法更改。除了在insert语句中将每个列和值指定为NULL之外,还有什么方法可以设置NULL吗。数据库是oracle 12
当然。您只需要枚举insert
语句中的目标列,不包括那些不想为其提供值的列。Oracle将为每列分配默认值(如果没有默认值,则为null
(。
假设你有下表:
create table mytable (
col1 int not null primary key,
col2 int not null,
col3 int default 0, -- has a default
col4 int, -- has no default
col5 int
);
你可以做:
insert into mytable (col1, col2)
values (1, 2);
你会得到:
COL1|COL2|COL3|COL4|COL5---:|---:|---1|2|0|null|null
当然,如果任何列被定义为not null
并且没有默认值,则此操作将失败,并出现错误ORA-01400: cannot insert NULL into ...
。