在UPDATE期间触发列的默认值 [英] Trigger default value of a column during UPDATE

查看:99
本文介绍了在UPDATE期间触发列的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道Oracle 12c的这种情况;

I am wondering about this case with Oracle 12c;

  1. 表X的A列为默认值'default'NOT NULL修饰符
  2. 我在表X中插入了新行,并且列A的值为'not-default'
  3. 我希望将上一行的A列更新为给定列的默认值,即'default'
  1. Table X has column A, with default value 'default' and NOT NULL modifier
  2. I insert a new row into Table X, and column A has value 'not-default'
  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆