[英]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.