Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a temporary table to permanent table in Oracle and vice versa

I would like to know which is the command to convert a temporary table to permanent table in Oracle.

Other issue is about the index. An index used in a temporary table will be the same used in a permanent table, if I convert it?

like image 920
willian Avatar asked Jan 23 '13 16:01

willian


People also ask

How do I change a global temporary table in Oracle?

A temporary table can be altered in the same way as a permanent base table although there is no official support to toggle the behavior of the ON COMMIT clause. The specification offers an ALTER TABLE syntax to toggle that behavior.

Can you convert a permanent table to a transient table?

Permanent tables have a Fail-safe period similar to transient tables and provide additional security of data recovery and protection. Presently, the permanent table cannot be modified to Transient Table using ALTER TABLE command.

What is the difference between a permanent and temporary table?

A permanent table ( materialized table) is stored as a file in hard disks. The temporary table just lives in a transaction. In addition, a global temp table could be alive outside transaction, but not really stored.


1 Answers

You can't convert a table from a temporary table to a permanent table.

You can create a new permanent table that matches the structure of the temporary table

CREATE TABLE new_permanent_table
AS
SELECT *
  FROM old_temporary_table
 WHERE 1=0;

Or you could get the DDL for the temporary table using the DBMS_METADATA package and manually edit the DDL to create the new permanent table.

Then you can create whatever indexes you would like on the new permanent table and drop the old temporary table. Once the old temporary table is dropped, you can rename the permanent table to use the name of the old temporary table if you would like.

like image 75
Justin Cave Avatar answered Oct 19 '22 03:10

Justin Cave