-1

尝试更改列的数据类型时,我不断收到此错误消息:

alter table x modify column order_date date NOT NULL;

第 1 行的错误

ORA-00905 缺少关键字

我不确定我哪里出错了,因为我知道 sql 中有很多类型的日期?

非常感谢

4

1 回答 1

3

MODIFY 子句不将 COLUMN 作为关键字。这将起作用:

alter table x modify order_date date NOT NULL;

Oracle SQL 参考中记录了该语法。 了解更多

我们只需要将 COLUMN 包含在具有多种不同可能性的命令中。例如,使用 ALTER TABLE ... DROP 命令,因为我们可以删除列、约束或分区...。

alter table x drop column order_date ;

“当我尝试输入 NOT NULL 时,它说表需要为空”

You should be able to apply a NOT NULL constraint, providing all the rows in the table have a value in the order_date column. The error message you get is quite clear:

ORA-01758 table must be empty to add mandatory (NOT NULL) column

This means your column has some rows without values. So, you need to update the table and populate those rows with some value; what you will use as a default depends on your business rules.

于 2013-04-07T20:40:47.090 回答