簡體   English   中英

Oracle SQL 開發人員 ORA-00904 在更改表上

[英]Oracle SQL Developer ORA-00904 on alter table

我目前正在嘗試更改 Oracle Z9778840A0100B30BCA2Z 中的現有 Oracle SQL 表。

我想向現有表中添加一個字段。 該字段不應為 null,鍵入 NVARCHAR(256) 並存儲一個簡單的字符串 - 不需要外鍵。

我的 SQL 看起來像這樣:

alter table MYTABLE
add column FRUITS NVARCHAR2(256) not null default 'apple';

當我運行此 sql 語句時,我收到以下錯誤:

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>

語法現在是正確的。 添加后刪除,並在“蘋果”后放置非 null

alter table MYTABLE
add  FRUITS NVARCHAR2(256)  default 'apple' not null;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM