简体   繁体   中英

INVALID ALTER TABLE OPTION on adding column

I am trying to add a new column to an already existing table. I am using Oracle 12c. The SQL Code goes like this:

ALTER TABLE table_name 
ADD column_name VARCHAR(120) 
DEFAULT 'Test' NOT NULL;

I am getting Error Msg = ORA-01735: Invalid ALTER TABLE option . What am i doing wrong?

SOLVED, PLEASE DELETE

I had a project-specific error while compiling my SQL statement, the problem has been solved and there was nothing wrong with the statement to begin with.

Your brackets are wrong, it must be

alter table job_details add (sched_name varchar2(120) DEFAULT 'TestScheduler' not null);

or

alter table job_details add sched_name varchar2(120) DEFAULT 'TestScheduler' not null;

That's rather simple;

SQL> create table table_name (id number);

Table created.

SQL> alter table table_name add
  2    column_name varchar(120)
  3    default 'Test'
  4    not null;

Table altered.

SQL>

Though, saying that "your console outputs ...", what is the console ? Which tool do you use?

[EDIT - everything included into the CREATE TABLE statement]

SQL> create table table_name
  2    (id           number,
  3     column_name  varchar2(120) default 'Test' not null
  4    );

Table created.

SQL>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM