[英]invalid ALTER TABLE option after changing a value to not null
create table agenda
(
id number(3),
first_name varchar(20),
last_name varchar2(20),
phone_nr char(14)
);
alter table agenda
alter column phone_nr char(14) not null;
在我尝试将phone_nr
变量更改phone_nr
空后,出现错误
无效的 ALTER TABLE 选项
我是 SQL 的初学者,我真的不明白问题出在哪里。
AFAIK,您不能使用alter column
子句来更改列的可为空性,但您可以使用modify column
子句:
alter table agenda modify column phone_nr char(14) not null;
-- Here -----------^
您是否确保所有phone_nr
值都设置为不为空的值? 你只能alter
它是not null
,如果所有的值都是一些不为空,否则会自相矛盾,因为它的价值将是null
,即使表说,它不能null
。 你可以试试这个:
UPDATE agenda SET phone_nr = '0-000-000-0000' WHERE phone IS NULL;
现在,由于所有为 null 的phone_nr
值都设置为非 null 的值,因此您可以在表中将其alter
为NOT NULL
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.