Using create table as select
In this recipe we will see how to create a table as the result of a selection from other tables or views in the database.
How to do it...
The following steps demonstrate how to use use selection to create a table:
- Connect to the
SH
schema:CONNECT sh@TESTDB/sh
- Create the empty table
MY_SALES
, and copy theSALES
table structure:CREATE TABLE MY_SALES AS SELECT * FROM SALES WHERE ROWNUM < 1;
- Insert all the rows from the
SALES
table intoMY_SALES
using direct path inserting :SET TIMING ON INSERT /*+ APPEND */ INTO MY_SALES SELECT * FROM SALES; SET TIMING OFF
- Drop the
MY_SALES
table:DROP TABLE MY_SALES;
- Create table
MY_SALES
as a selection fromSALES
table:SET TIMING ON CREATE TABLE MY_SALES AS SELECT * FROM SALES; SET ...
Get Oracle Database 11gR2 Performance Tuning Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.