Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter table after keyword in Oracle

ALTER TABLE testTable ADD column1 NUMBER(1) DEFAULT 0 NOT NULL AFTER column2;

Why can't I use mySql syntax in Oracle too? The above command works in MySql. Can you give me an equivalent that works?


Error report:
SQL Error: ORA-01735: invalid ALTER TABLE option
01735. 00000 -  "invalid ALTER TABLE option"

I am asking if there is any way to use after clause in Oracle command that I provided?

like image 207
radu florescu Avatar asked Jan 19 '12 07:01

radu florescu


People also ask

How will you ALTER TABLE in Oracle?

To MODIFY a column in an existing table, the Oracle ALTER TABLE syntax is: ALTER TABLE customers MODIFY column_name column_type; ALTER TABLE MODIFY allows modifying the constraints such as primary key, column size, type, its default value, length, nullability, etc. Here is an example of modifying the first_name column.

Can we ALTER TABLE with data in Oracle?

The Oracle ALTER TABLE statement is used to add, modify, or drop/delete columns in a table. The Oracle ALTER TABLE statement is also used to rename a table.

Do we need to commit after ALTER TABLE?

ALTER TABLE is a DDL command, and all DDL command is "auto-committing", so you don't need to commit. ALTER TABLE is a DDL command, and as any DDL command is "auto-committing", so you don't need to commit.


1 Answers

Because SQL is a relational algebra. It doesn't care one bit about "where" columns are located within a table, only that they exist.

To get it to work in Oracle, just get rid of the after clause. The Oracle documentation for alter table is here but it boils down to:

alter table testTable
    add ( column1 number(1) default 0 not null )

There is no after clause for the alter table command.

like image 159
paxdiablo Avatar answered Sep 20 '22 13:09

paxdiablo