Question: I
need to understand how to create table
using CTAS. Can you show an example a create table
using CTAS?Answer:
The create table using CTAS command is very
straightforward:
The Create table as select (CTAS) statement can be used
to change storage parameters for a table (INITIAL, NEXT,
FREELISTS) and also change the physical sequence of the
table rows. Create table as select (CTAS) has the following
syntax:
create
table
xxx_new
tablespace
new_tablespace_name
storage
(initial
new_initial next new_next freelists new_freelist_number )
as
select
*
from
xxx
order by
primary_index_key_values;
There are several way to execute CTAS to reorganize
table; many of the options depend upon the version of Oracle
and the particular configuration of the Oracle database.
Create table with
Parallel CTAS
Running a create table as
select (CTAS) in parallel can dramatically speed up SAP
table reorganization. As a rule of thumb, the parallel
option is used only on SAP database servers that have
multiple CPUs (for example, SMP processor CPUs), but there
will be some performance improvement when invoking
parallelism, even on a uni-processor CPU.
Note that the UNRECOVERABLE clause can be used in
conjunction with the parallel clause, or you can run
UNRECOVERABLE CTAS without using parallelism. Here is an
example of a parallel CTAS:
create table
vbap_sorted
tablespace
vbap_copy
storage (
initial 500m
next 50m
maxextents unlimited
)
parallel (degree 4)
as
select *
from
sapr3.vbap
order by
mandt,
vbeln,
posnr;
Create table
with CTAS using INDEX hint
This is an excellent way of reorganizing a table to
physically re-sequence the rows in the table. It is commonly
known that Oracle deliberately omitted the ORDER BY clause
in their implementation of CREATE TABLE AS SELECT. This is
because of Oracle's early philosophy (pre-release 7.3.4 on
AIX) that the physical sequence of rows within a table
should not matter to the performance of the system.
Unfortunately, this is not the case. As any DB2 professional
is aware, "clustering" the rows in a table in the same order
as the primary key index can greatly improve the performance
of the queries.
Note: Some
releases of Oracle prior to 7.3.4 may support ORDER BY with
CTAS, but for AIX 7.3.3 and before generate a syntax error
when ORDER BY is used with CTAS. Oracle does allow the use
of the INDEX "hint" to request an ordered copy of the table.
Here is an example of INDEX hint with CTAS.
create table vbap_sorted
tablespace vbap_copy
storage (initial 500m
next
50m
freelists 30
maxextents unlimited
)
as
select /*+ index(vbap vbap___0) */
*
from
sapr3.vbap
;
See these related notes on create table with CTAS:
|
|
|
Oracle Training from Don Burleson
The best on site
"Oracle
training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

|
|
|
|
|
Burleson is the American Team

Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright © 1996 - 2020
All rights reserved by
Burleson
Oracle ®
is the registered trademark of Oracle Corporation.
|
|