问题描述
我目前正在尝试更改 Oracle sql Developer 中现有的 Oracle sql 表。
我想向现有表中添加一个字段。 该字段不应为空,键入 NVARCHAR(256) 并存储一个简单的字符串 - 不需要外键。
我的 sql 如下所示:
alter table MYTABLE
add column FRUITS NVARCHAR2(256) not null default 'apple';
Error starting at line : 1 in command -
alter table MYTABLE
add column FRUITS NVARCHAR2(256) not null default 'apple'
Error report -
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
解决方法
错误的语法以及错误的约束顺序。
应该
alter table MYTABLE
add FRUITS NVARCHAR2(256) default 'apple' not null;
演示:
SQL> create table mytable (id number);
Table created.
SQL> alter table MYTABLE
2 add column FRUITS NVARCHAR2(256) not null default 'apple';
add column FRUITS NVARCHAR2(256) not null default 'apple'
*
ERROR at line 2:
ORA-00904: : invalid identifier
SQL> alter table MYTABLE
2 add FRUITS NVARCHAR2(256) not null default 'apple';
add FRUITS NVARCHAR2(256) not null default 'apple'
*
ERROR at line 2:
ORA-30649: missing DIRECTORY keyword
SQL> alter table MYTABLE
2 add FRUITS NVARCHAR2(256) default 'apple' not null;
Table altered.
SQL>
,
语法现在是正确的。添加后删除列并将非空放在'apple'
之后alter table MYTABLE
add FRUITS NVARCHAR2(256) default 'apple' not null;