Oracle table name change

I am trying to change the table name in oracle. First I run this script to declare a table

CREATE TABLE CUSTOMER ( C_ID NUMBER(6,0), C_LAST VARCHAR2(25), C_FIRST varchar2(25), C_MI char(1), C_DOB DATE, C_ADDRESS varchar2(100), C_CITY varchar2(35), C_STATE char(2), C_ZIP varchar2(10), C_DPHONE varchar2(12), C_EPHONE varchar2(12), C_USERID varchar2(20), C_PASSWORD VARCHAR2(30), CONSTRAINT CUSTOMER_PK PRIMARY KEY(C_ID) ); CREATE TABLE ORDER_SOURCE ( OS_ID NUMBER(6), OS_DESC varchar2(255), CONSTRAINT ORDER_SOURCE_PK PRIMARY KEY(OS_ID) ); CREATE TABLE ORDERS ( O_ID NUMBER(6), O_DATE DATE, O_METHPMT varchar2(25), C_ID NUMBER(6), OS_ID NUMBER(6), CONSTRAINT ORDERS_PK PRIMARY KEY(O_ID), CONSTRAINT ORDERS_CUSTOMER_FK FOREIGN KEY(C_ID) REFERENCES CUSTOMER(C_ID), CONSTRAINT ORDERS_ORDER_SOURCE_FK FOREIGN KEY(OS_ID) REFERENCES ORDER_SOURCE(OS_ID) ); 

It works correctly, then I try to run

 alter table ORDERS rename to ORDER; 

I get this error:

Error starting with line 1 in the command: change table ORDERS rename ORDER Error report: SQL error: ORA-00903: invalid table name 00903. 00000 - "invalid table name" * Cause:
* Action:

+4
source share
3 answers

order is a reserved word in oracle, so you cannot use it as a table name. You can try double quotes ("order"), but this is not a good practice.

+4
source

The syntax " RENAME TABLE tab_old TO tab_new " is RENAME TABLE tab_old TO tab_new . The correct syntax is " RENAME tab_old TO tab_new ".
The word "TABLE" should not be in the instructions.

+32
source
 RENAME TABLE table-Name TO new-Table-Name 

If there is a view or foreign key that references the table, attempts to rename it will cause an error. In addition, if there are any control restrictions or triggers in the table, attempts to rename will also generate an error.

And in your case, the name of the table "ORDER" is reserved, so try changing the name

0
source

Source: https://habr.com/ru/post/1444857/


All Articles