Rename Oracle Table or View

前端 未结 5 1082
情歌与酒
情歌与酒 2020-12-13 23:27

What is the syntax to rename a table or view in Oracle?

相关标签:
5条回答
  • 2020-12-13 23:42
    ALTER TABLE mytable RENAME TO othertable
    

    In Oracle 10g also:

    RENAME mytable TO othertable
    
    0 讨论(0)
  • 2020-12-13 23:46

    In order to rename a table in a different schema, try:

    ALTER TABLE owner.mytable RENAME TO othertable;
    

    The rename command (as in "rename mytable to othertable") only supports renaming a table in the same schema.

    0 讨论(0)
  • 2020-12-13 23:54

    Past 10g the current answer no longer works for renaming views. The only method that still works is dropping and recreating the view. The best way I can think of to do this would be:

    SELECT TEXT FROM ALL_VIEWS WHERE owner='some_schema' and VIEW_NAME='some_view';

    Add this in front of the SQL returned

    Create or replace view some_schema.new_view_name as ...

    Drop the old view

    Drop view some_schema.some_view;

    0 讨论(0)
  • 2020-12-13 23:57

    One can rename indexes the same way:

    alter index owner.index_name rename to new_name;
    
    0 讨论(0)
  • 2020-12-14 00:01

    To rename a table you can use:

    RENAME mytable TO othertable;
    

    or

    ALTER TABLE mytable RENAME TO othertable;
    

    or, if owned by another schema:

    ALTER TABLE owner.mytable RENAME TO othertable;
    

    Interestingly, ALTER VIEW does not support renaming a view. You can, however:

    RENAME myview TO otherview;
    

    The RENAME command works for tables, views, sequences and private synonyms, for your own schema only.

    If the view is not in your schema, you can recompile the view with the new name and then drop the old view.

    (tested in Oracle 10g)

    0 讨论(0)
提交回复
热议问题