简体   繁体   English

如果字段值为空,则更新字段值

[英]Updating field value if it is null

I think this is a simple question but I haven't touched in Oracle SQL for a while.我认为这是一个简单的问题,但我有一段时间没有接触过 Oracle SQL。

I want to update a table if a certain field value is null.如果某个字段值为空,我想更新一个表。

I'm not sure if I should use the "not exists" clause, and this is what I have so far:我不确定是否应该使用“不存在”子句,这就是我目前所拥有的:

update table_classroom
set cod_classroom = 'unknown'
where exists (select * from table_classroom where cod_classroom is null)

Is this correct?这样对吗?

Even simpler:更简单:

update table_classroom
set cod_classroom = 'unknown'
where cod_classroom is null

Perhaps you also want to omit future entries where cod_classroom is null.也许您还想省略 cod_classroom 为空的未来条目。 If this is the case you don't need to update the column manually but you can include this in your alter statement:如果是这种情况,您不需要手动更新列,但您可以将其包含在您的更改语句中:

ALTER TABLE table_classroom MODIFY (cod_classroom NOT NULL DEFAULT 'unknown')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM