在Oracle中對字段進行操作的時候和MySQL是有些許不同的.
大部分修改字段都是在建表之後或者數據庫中已有數據的時候,我們需要注意的有以下幾點:
1.添加字段:
alter table fnd_emp add (字段名 屬性值 默認值 約束);
#例子:
alter table fnd_emp add (emp_email varchar(50) default '**********@***.com' not null);
注意:因爲是已有數據,所以我們進行添加字段的時候如果有約束,比如not null我們就必須給予默認值,或者其他數據
2.1修改字段屬性:
alter table fnd_emp modify (字段名 屬性值);
#例子:
alter table fnd_emp modify (email varchar(52));
2.2修改字段名:
alter table fnd_emp rename column 舊的名字 to 新的名字;
#例子:
alter table fnd_emp rename column email to eemail;
3.刪除字段
問題寫法:
alter table fnd_emp drop 字段名;
alter table fnd_emp drop email;
×--------↑
↓
正確寫法:
alter table fnd_emp drop (字段名);
alter table fnd_emp drop (email);
注意:刪除字段的時候最好是添加括號把字段名括起來不然就是這個缺失關鍵字報錯.