重命名Oracle表

3
ALTER TABLE RENAME语句和RENAME TABLE语句有什么区别?
即,两者之间的区别是什么?
Alter table old_table_name rename to new_table_name

并且
rename table old_table_name to new_table_name.

这可能是你问题的答案:https://dev59.com/43RA5IYBdhLWcg3wxA1N#835782 - Vytautas Alkimavičius
简单的 rename 仅适用于对象存在的相同模式,而 alter 可以从其他模式中进行操作。当然,前提是您具有所需的权限。请参阅我的答案。 - Lalit Kumar B
可能是[重复问题]的一个例子:重命名Oracle表或视图 - Sathyajith Bhat
1个回答

13

将旧表名重命名为新表名:rename old_table_name to new_table_name。

此语法不正确,不需要使用table关键字。正确的语法是 -

rename old_table_name to new_table_name;

现在,让我们看看alter语句和简单的rename语句之间的区别。

我有两个模式:SCOTTLALIT

SQL> SHOW USER
USER is "SCOTT"
SQL>
SQL> create table t(id number);

Table created.

SQL> rename t to t_new;

Table renamed.

SQL> alter table t_new rename to t_newer;

Table altered.

因此,这两个语句在同一模式中运行。

让我们连接到另一个模式 -

SQL> SHOW USER
USER is "LALIT"
SQL>
SQL> create table t(id number);

Table created.

SQL> rename scott.t_newer to t_newest;
rename scott.t_newer to t_newest
       *
ERROR at line 1:
ORA-01765: specifying owner's name of the table is not allowed


SQL> alter table scott.t_newer rename to t_newest;

Table altered.

因此,您看到了错误ORA-01765:不允许指定表的所有者名称。这就是简单的rename语句在其他模式对象上失败的地方。只有ALTER语句有效。


不用谢。如果您已经得到了解决方案,请标记为已回答。 - Lalit Kumar B

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接