在UPDATE期间触发列的默认值 [英] Trigger default value of a column during UPDATE
问题描述
我想知道Oracle 12c的这种情况;
I am wondering about this case with Oracle 12c;
- 表X的A列为默认值
'default'
和NOT NULL
修饰符 - 我在表X中插入了新行,并且列A的值为
'not-default'
- 我希望将上一行的A列更新为给定列的默认值,即
'default'
- Table X has column A, with default value
'default'
andNOT NULL
modifier - I insert a new row into Table X, and column A has value
'not-default'
- I wish to update column A of the above row to the default value of the given column, namely
'default'
有不知道默认值的简短方法吗?我可以做类似的事情吗?
Is there a short way of doing this without knowing the default value? Can I do something like;
UPDATE X SET A = DEFAULT_VAL(A) WHERE ...
尝试更新为null显然会触发ORA-01407: cannot update ("schema"."X"."A") to NULL
,我想知道Oracle上是否有这样的功能.
Trying to update to null obviously triggers a ORA-01407: cannot update ("schema"."X"."A") to NULL
, I'd like to know if there is such a feature on Oracle.
推荐答案
我们可以在update和insert语句中使用默认关键字. 例如
We can you default keyword in update and insert statement. eg
update x set A = default where ...
这将对您的情况有帮助,在其他情况下,例如我不想在插入语句中添加列子句
This will be helpful for your case and also in another case like i don't want add column clause in insert statement like
insert into table values (val1, val2, default);
如果我们不能使用默认值,那么我们必须添加列子句,相同的查询将如下所示
If we couldn't use default then we have to add column clause, same query will be like below
insert into table (col1, col2, col3) values (val1, val2, default);
这篇关于在UPDATE期间触发列的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!