简体   繁体   English

从SQL中的不可为空的列中删除数据

[英]Delete Data from Non-Nullable Column in SQL

Question: I have table with three column, with column names APP_NAME, APP_TYPE and VALUE_TIME. 问题:我的表具有三列,列名称为APP_NAME,APP_TYPE和VALUE_TIME。

在此处输入图片说明

I would like to edit VALUE_TIME for particular APP_NAME and APP_TYPE. 我想为特定的APP_NAME和APP_TYPE编辑VALUE_TIME。 So my query should look like below mentioned if VALUE_TIME column is Nullable. 因此,如果VALUE_TIME列为Nullable,我的查询应如下所示。 So what would be the best way to delete the data for particular condition ? 那么,针对特定条件删除数据的最佳方法是什么?

UPDATE TABLE_NAME
SET VALUE_TIME = null
WHERE APP_NAME = 'XYZ'
AND APP_TYPE = 'TEST'; 

Thanks 谢谢

If you want to delete the row: 如果要删除该行:

DELETE TABLE_NAME WHERE APP_NAME = 'XYZ' AND APP_TYPE = 'TEST'; 

The column VALUE_TYPE is defined as NOT NULL, so you can't set it to null. 列VALUE_TYPE被定义为NOT NULL,因此您不能将其设置为null。 You could alter the table to make it nullable: 您可以更改表以使其可为空:

ALTER TABLE TABLE_NAME MODIFY VALUE_TYPE VARCHAR2(500) NULL;

And then run the UPDATE statement in your question. 然后在您的问题中运行UPDATE语句。

Hopefully this answers your question - it wasn't clear what you want to do exactly. 希望这能回答您的问题-尚不清楚您要确切地做什么。

Simple Answer, You can't update non-nullable column data to NULL or ' ' in oracle. 简单的答案,您不能在oracle中将不可为空的列数据更新为NULL或''。 I could only think of is Alter the column to have null. 我只能想到的是Alter列具有null。

ALTER 
TABLE TABLE_NAME 
MODIFY VALUE_TYPE VARCHAR2(500) NULL

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

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