Oracle8i SQL Reference Release 3 (8.1.7) Part Number A85397-01 |
|
SQL Statements:
CREATE SYNONYM to DROP ROLLBACK SEGMENT, 3 of 31
Use the CREATE
TABLE
statement to create one of the following types of tables:
You can also create an object type and then use it in a column when creating a relational table.
Tables are created with no data unless a query is specified. You can add rows to a table with the INSERT
statement. After creating a table, you can define additional columns, partitions, and integrity constraints with the ADD
clause of the ALTER
TABLE
statement. You can change the definition of an existing column or partition with the MODIFY
clause of the ALTER
TABLE
statement.
See Also:
Oracle8i Application Developer's Guide - Fundamentals and CREATE TYPE for more information about creating objects |
To create a relational table in your own schema, you must have system privilege. To create a table in another user's schema, you must have CREATE
ANY
TABLE
system privilege. Also, the owner of the schema to contain the table must have either space quota on the tablespace to contain the table or UNLIMITED
TABLESPACE
system privilege.
In addition to the table privileges above, to create an object table (or a relational table with an object type column, the owner of the table must have the EXECUTE
object privilege in order to access all types referenced by the table, or you must have the EXECUTE
ANY
TYPE
system privilege. These privileges must be granted explicitly and not acquired through a role.
Additionally, if the table owner intends to grant access to the table to other users, the owner must have been granted the EXECUTE
privileges to the referenced types with the GRANT
OPTION
, or have the EXECUTE
ANY
TYPE
system privilege with the ADMIN
OPTION
. Without these privileges, the table owner has insufficient privileges to grant access on the table to other users.
To enable a UNIQUE
or PRIMARY
KEY
constraint, you must have the privileges necessary to create an index on the table. You need these privileges because Oracle creates an index on the columns of the unique or primary key in the schema containing the table.
See Also:
|
relational_table
::=
object_table
::=
subquery
::= See SELECT and subquery.
table_constraint
, column_constraint
, table_ref_constraint
, column_ref_constraint
, constraint_state
: See the constraint_clause
storage_clause
: See the storage_clause.
index_organized_table_clause::=
index_organized_overflow_clause
::=
nested_table_storage_clause::=
composite_partitioning_clause::=
partition_level_subpartitioning::=
hash_partitioning_storage_clause
::=
global_index_clause
::=
global_partition_clause
::=
GLOBAL
TEMPORARY
Specify GLOBAL
TEMPORARY
to indicate that the table is temporary and that its definition is visible to all sessions. The data in a temporary table is visible only to the session that inserts the data into the table.
A temporary table has a definition that persists the same as the definitions of regular tables, but it contains either session-specific or transaction-specific data. You specify whether the data is session- or transaction-specific with the ON
COMMIT
keywords (below).
Restrictions:
LOB_storage_clause
: TABLESPACE
, storage_clause
, LOGGING
or NOLOGGING
, MONITORING
or NOMONITORING
, or LOB_index_clause
.
segment_attributes_clause
, nested_table_storage_clause
, or parallel_clause
.
schema
Specify the schema to contain the table. If you omit schema
, Oracle creates the table in your own schema.
table
Specify the name of the table (or object table) to be created.
OF
object_type
The OF
clause lets you explicitly creates an object table of type object_type
. The columns of an object table correspond to the top-level attributes of type object_type
. Each row will contain an object instance, and each instance will be assigned a unique, system-generated object identifier (OID) when a row is inserted. If you omit schema
, Oracle creates the object table in your own schema.
Objects residing in an object table are referenceable.
See Also:
|
relational_properties
|
Specify the name of a column of the table.
If you also specify |
|
|
The absolute maximum number of columns in a table is 1000. However, when you create an object table (or a relational table with columns of object, nested table, varray, or REF type), Oracle maps the columns of the user-defined types to relational columns, creating in effect "hidden columns" that count toward the 1000-column limit. For details on how Oracle calculates the total number of columns in such a table, please refer to Oracle8i Administrator's Guide. |
|
|
Specify the datatype of a column.
Restrictions: |
|
|
Note: You can omit
|
|
|
The
Restriction: A
|
|
|
These clauses let you further describe a column of type |
|
|
Use the
You can create |
|
|
Use the |
|
|
object_properties
The properties of object tables are essentially the same as those of relational tables. However, instead of specifying columns, you specify attributes of the object.
|
Specify the qualified column name of an item in an object. |
ON
COMMIT
The ON
COMMIT
clause is relevant only if you are creating a temporary table. This clause specifies whether the data in the temporary table persists for the duration of a transaction or a session.
OID_clause
The OID_clause
lets you specify whether the object identifier (OID) of the object table should be system generated or should be based on the primary key of the table. The default is SYSTEM
GENERATED
.
Restrictions:
OBJECT
IDENTIFIER
IS
PRIMARY
KEY
unless you have already specified a PRIMARY
KEY
constraint for the table.
OID_index_clause
This clause is relevant only if you have specified the OID_clause
as SYSTEM
GENERATED
. It specifies an index, and optionally its storage characteristics, on the hidden object identifier column.
|
Specify the name of the index on the hidden system-generated object identifier column. If not specified, Oracle generates a name. |
physical_properties
segment_attributes_clause
|
The |
|
|
|
|
|
Specify the percentage of space in each data block of the table, object table OID index, or partition reserved for future updates to the table's rows. The value of |
|
|
|
|
|
Specify the minimum percentage of used space that Oracle maintains for each data block of the table, object table OID index, or index-organized table overflow data segment. A block becomes a candidate for row insertion when its used space falls below |
|
|
|
|
|
|
|
|
The sum of
|
|
|
Specify the initial number of transaction entries allocated within each data block allocated to the table, object table OID index, partition, LOB index segment, or overflow data segment. This value can range from 1 to 255 and defaults to 1. In general, you should not change the |
|
|
Each transaction that updates a block requires a transaction entry in the block. The size of a transaction entry depends on your operating system. |
|
|
This parameter ensures that a minimum number of concurrent transactions can update the block and helps avoid the overhead of dynamically allocating a transaction entry. |
|
|
The |
|
|
Specify the maximum number of concurrent transactions that can update a data block allocated to the table, object table OID index, partition, LOB index segment, or index-organized overflow data segment. This limit does not apply to queries. This value can range from 1 to 255 and the default is a function of the data block size. You should not change the |
|
|
If the number of concurrent transactions updating a block exceeds the |
|
|
The |
|
|
The |
|
|
Specify the tablespace in which Oracle creates the table, object table OID index, partition, LOB storage, LOB index segment, or index-organized table overflow data segment. If you omit |
|
|
For heap-organized tables with one or more LOB columns, if you omit the
However, for an index-organized table with one or more LOB columns, if you omit |
|
|
For nonpartitioned tables, the value specified for |
|
|
|
|
|
Specify whether the creation of the table (and any indexes required because of constraints), partition, or LOB storage characteristics will be logged in the redo log file (
This attribute also specifies that subsequent Direct Loader (SQL*Loader) and direct-load |
|
|
For a table or table partition, if you omit this clause, the logging attribute of the table or table partition defaults to the logging attribute of the tablespace in which it resides. |
|
|
For LOBs, if you omit this clause,
|
|
|
For nonpartitioned tables, the value specified for |
|
|
In |
|
|
The size of a redo log generated for an operation in
If the database is run in |
|
|
|
|
|
These keywords are deprecated and have been replaced with |
|
|
Restrictions: |
ORGANIZATION
The ORGANIZATION
clause lets you specify the order in which the data rows of the table are stored.
index_organized_table_clause
Use the index_organized_table_clause
to instruct Oracle to maintain the table rows (both primary key column values and non-key column values) in a B*-tree index built on the primary key. Index-organized tables are therefore best suited for primary key-based access and manipulation. An index-organized table is an alternative to
CREATE
INDEX
statement
CREATE
CLUSTER
statement that maps the primary key for the table to the cluster key
Restrictions:
ROWID
for an index-organized table.
CLUSTER
The CLUSTER
clause indicates that the table is to be part of cluster
. The columns listed in this clause are the table columns that correspond to the cluster's columns. Generally, the cluster columns of a table are the column or columns that make up its primary key or a portion of its primary key.
Specify one column from the table for each column in the cluster key. The columns are matched by position, not by name.
A clustered table uses the cluster's space allocation. Therefore, do not use the PCTFREE
, PCTUSED
, INITRANS
, or MAXTRANS
parameters, the TABLESPACE
clause, or the storage_clause
with the CLUSTER
clause.
Restrictions: Object tables and tables containing LOB columns cannot be part of a cluster.
LOB_storage_clause
The LOB_storage_clause
lets you specify the storage attributes of LOB data segments.
physical_properties
clause without any of the partitioning clauses), this clause specifies the table's storage attributes of LOB data segments.
physical_properties
clause along with one of the partitioning clauses), this clause specifies the default storage attributes for LOB data segments associated with each partition or subpartition. These storage attributes apply to all partitions or subpartitions unless overridden by a LOB_storage_clause
at the partition or subpartition level.
partition_definition
), this clause specifies the storage attributes of the data segments of that partition or the default storage attributes of any subpartitions of this partition. A partition-level LOB_storage_clause
overrides a table-level LOB_storage_clause
.
subpartition_clause
), this clause specifies the storage attributes of the data segments of this subpartition. A subpartition-level LOB_storage_clause
overrides both partition-level and table-level LOB_storage_clauses
.
Restriction: You cannot specify the LOB_index_clause
if table is partitioned.
See Also:
|
|
Specify the LOB column name or LOB object attribute for which you are explicitly defining tablespace and storage characteristics that are different from those of the table. Oracle automatically creates a system-managed index for each |
|
|
Specify the name of the LOB data segment. You cannot use |
|
|
The |
|
|
|
If you enable storage in row, the LOB value is stored in the row (inline) if its length is less than approximately 4000 bytes minus system control information. This is the default.
Restriction: For an index-organized table, you cannot specify this parameter unless you have specified an |
|
|
If you disable storage in row, the LOB value is stored outside of the row regardless of the length of the LOB value. |
|
The LOB locator is always stored in the row regardless of where the LOB value is stored. You cannot change the value of |
|
|
|
Specify the number of bytes to be allocated for LOB manipulation. If
You cannot change the value of |
|
|
|
|
|
Specify the maximum percentage of overall LOB storage space used for creating new versions of the LOB. The default value is 10, meaning that older versions of the LOB data are not overwritten until 10% of the overall LOB storage space is used. |
|
This clause is deprecated as of Oracle8i. Oracle generates an index for each LOB column. Oracle names and manages the LOB indexes internally. Although it is still possible for you to specify this clause, Oracle Corporation strongly recommends that you no longer do so. In any event, do not put the LOB index in a different tablespace from the LOB data.
|
varray_storage_clause
The varray_storage_clause
lets you specify separate storage characteristics for the LOB in which a varray will be stored. In addition, if you specify this clause, Oracle will always store the varray in a LOB, even if it is small enough to be stored inline.
physical_properties
clause without any of the partitioning clauses), this clause specifies the storage attributes of the varray's LOB data segments.
physical_properties
clause along with one of the partitioning clauses), this clause specifies the default storage attributes for the varray's LOB data segments associated with each partition (or its subpartitions, if any).
partition_definition
), this clause specifies the storage attributes of the varray's LOB data segments of that partition or the default storage attributes of the varray's LOB data segments of any subpartitions of this partition. A partition-level varray_storage_clause
overrides a table-level varray_storage_clause
.
subpartition_clause
), this clause specifies the storage attributes of the varray's data segments of this subpartition. A subpartition-level varray_storage_clause
overrides both partition-level and table-level varray_storage_clauses
.
Restriction: You cannot specify the TABLESPACE
parameter of LOB_parameters
as part of this clause. The LOB tablespace for a varray defaults to the containing table's tablespace.
nested_table_storage_clause
The nested_table_storage_clause
lets you to specify separate storage characteristics for a nested table, which in turn enables you to define the nested table as an index-organized table. The storage table is created in the same tablespace as its parent table (using the default storage characteristics) and stores the nested table values of the column for which it was created.
You must include this clause when creating a table with columns or column attributes whose type is a nested table. (Clauses within this clause that function the same way they function for parent object tables are not repeated here.)
Restrictions:
OID_clause
.
TABLESPACE
(as part of the segment_attributes_clause
) for a nested table. The tablespace is always that of the parent table.
object_properties
) a table_ref_constraint
, column_ref_constraint
, or referential constraint for the attributes of a nested table. However, you can modify a nested table to add such constraints using ALTER
TABLE
.
ALTER
TABLE
statement.
|
Specify the name of a column (or a top-level attribute of the table's object type) whose type is a nested table. |
|
|
Specify the name of the table where the rows of |
|
|
Restriction: You cannot partition the storage table of a nested table. |
|
|
You cannot query or perform DML statements on See Also: ALTER TABLE for information about modifying nested table column storage characteristics |
|
|
Specify what Oracle returns as the result of a query. |
|
|
||
If you do not specify the |
table_properties
range_partitioning_clause
Use the range_partitioning_clause
to partition the table on ranges of values from column_list
. For an index-organized table, column_list
must be a subset of the primary key columns of the table.
hash_partitioning_clause
Use the hash_partitioning_clause
to specify that the table is to be partitioned using the hash method. Oracle assigns rows to partitions using a hash function on values found in columns designated as the partitioning key.
|
Specify an ordered list of columns used to determine into which partition a row belongs (the partitioning key). |
Restrictions:
column_list
.
column_list
cannot contain the ROWID
or UROWID
pseudocolumns.
column_list
can be of any built-in datatype except ROWID
, LONG
, or LOB.
You can specify hash partitioning in one of two ways:
SYS_P
nnn
. The STORE
IN
clause specifies one or more tablespaces where the hash partitions are to be stored. The number of tablespaces does not have to equal the number of partitions. If the number of partitions is greater than the number of tablespaces, Oracle cycles through the names of the tablespaces.
TABLESPACE
clause specifies where the partition should be stored.
composite_partitioning_clause
Use the composite_partitioning_clause to first partition table by range, and then partition the partitions further into hash subpartitions. This combination of range partitioning and hash subpartitioning is called composite partitioning.
partition_definition
|
Specify the physical partition attributes. If |
|
|
Notes:
|
|
|
Specify the noninclusive upper bound for the current partition.
Specifying a value other than
|
|
|
Note: If
|
|
|
The |
|
|
The |
|
|
The Restriction: You can specify this clause only for a composite-partitioned table. |
|
|
|
row_movement_clause
The row_movement_clause
lets you specify whether a row can be moved to a different partition or subpartition because of a change to one or more of its key values during an update operation.
Restriction: You can specify this clause only for a partitioned table.
CACHE
| NOCACHE
| CACHE READS
MONITORING
| NOMONITORING
parallel_clause
The parallel_clause
lets you parallelize creation of the table and set the default degree of parallelism for queries and DML on the table after creation.
Notes on the parallel_clause
table
contains any columns of LOB or user-defined object type, this statement as well as subsequent INSERT
, UPDATE
, or DELETE
operations on table
are executed serially without notification. Subsequent queries, however, will be executed in parallel.
CREATE
TABLE
... AS
SELECT
is executed serially, as are subsequent DML operations. Subsequent queries, however, will be executed in parallel.
parallel_clause
.
CREATE
TABLE
... AS
SELECT
statements that reference remote objects can run in parallel. However, the "remote object" must really be on a remote database. The reference cannot loop back to an object on the local database (for example, by way of a synonym on the remote database pointing back to an object on the local database).
See Also: Oracle8i Performance Guide and Reference, Oracle8i Concepts, and Oracle8i Parallel Server Concepts for more information on parallelized operations
enable_disable_clause
The enable_disable_clause
lets you specify whether Oracle should apply a constraint. By default, constraints are created in ENABLE
VALIDATE
state.
Restrictions:
|
Specify
|
|
|
|
|
|
|
|
|
|
|
|
||
|
Specify |
|
|
|
|
|
|
|
|
|
|
|
||
|
The |
|
|
The |
|
|
The |
using_index_clause
The using_index_clause
lets you specify parameters for the index Oracle creates to enforce a unique or primary key constraint. Oracle gives the index the same name as the constraint.
You can choose the values of the INITRANS
, MAXTRANS
, TABLESPACE
, STORAGE
, and PCTFREE
parameters for the index. These parameters are described earlier in this statement. If table
is partitioned, you can specify a locally or globally partitioned index for the unique or primary key constraint.
See Also: CREATE INDEX for a description of |
Restriction: Use these parameters only when enabling unique and primary key constraints.
EXCEPTIONS
INTO
Specify a table into which Oracle places the rowids of all rows violating the constraint. If you omit schema, Oracle assumes the exceptions table is in your own schema. If you omit this clause altogether, Oracle assumes that the table is named EXCEPTIONS
. The exceptions table must be on your local database.
You can create the EXCEPTIONS
table using one of these scripts:
UTLEXCPT.SQL
uses physical rowids. Therefore it can accommodate rows from conventional tables but not from index-organized tables. (See the Note that follows.)
UTLEXPT1.SQL
uses universal rowids, so it can accommodate rows from both conventional and index-organized tables.
If you create your own exceptions table, it must follow the format prescribed by one of these two scripts.
See Also:
|
CASCADE
Specify CASCADE
to disable any integrity constraints that depend on the specified integrity constraint. To disable a primary or unique key that is part of a referential integrity constraint, you must specify this clause.
Restriction: You can specify CASCADE
only if you have specified DISABLE
.
AS
subquery
Specify a subquery to determine the contents of the table. The rows returned by the subquery are inserted into the table upon its creation.
For object tables, subquery
can contain either one expression corresponding to the table type, or the number of top-level attributes of the table type.
Restrictions:
CREATE
TABLE
statement that contains AS
subquery
. Instead, you must create the table without the constraint and then add it later with an ALTER
TABLE
statement.
If you specify the parallel_clause
in this statement, Oracle will ignore any value you specify for the INITIAL
storage parameter, and will instead use the value of the NEXT
parameter.
Oracle derives datatypes and lengths from the subquery. Oracle also follows the following rules for integrity constraints:
NOT
NULL
constraints on columns in the new table that existed on the corresponding columns of the selected table if the subquery selects the column rather than an expression containing the column.
CREATE
TABLE
statement contains both AS
subquery
and a CONSTRAINT
clause or an ENABLE
clause with the EXCEPTIONS
INTO
clause, Oracle ignores AS
subquery
. If any rows violate the constraint, Oracle does not create the table and returns an error.
If all expressions in subquery
are columns, rather than expressions, you can omit the columns from the table definition entirely. In this case, the names of the columns of table are the same as the columns in subquery
.
You can use subquery
in combination with the TO_LOB
function to convert the values in a LONG
column in another table to LOB values in a column of the table you are creating.
See Also:
|
Note:
If See Also: Oracle8i Data Warehousing Guide for more information on materialized views and query rewrite |
|
The
|
|
|
|
To define the emp
table owned by scott
, you could issue the following statement:
CREATE TABLE scott.emp (empno NUMBER CONSTRAINT pk_emp PRIMARY KEY, ename VARCHAR2(10) CONSTRAINT nn_ename NOT NULL CONSTRAINT upper_ename CHECK (ename = UPPER(ename)), job VARCHAR2(9), mgr NUMBER CONSTRAINT fk_mgr REFERENCES scott.emp(empno), hiredate DATE DEFAULT SYSDATE, sal NUMBER(10,2) CONSTRAINT ck_sal CHECK (sal > 500), comm NUMBER(9,0) DEFAULT NULL, deptno NUMBER(2) CONSTRAINT nn_deptno NOT NULL CONSTRAINT fk_deptno REFERENCES scott.dept(deptno) ) PCTFREE 5 PCTUSED 75;
This table contains eight columns. The empno
column is of datatype NUMBER
and has an associated integrity constraint named pk_emp
. The hiredate
column is of datatype DATE
and has a default value of SYSDATE
, and so on.
This table definition specifies a PCTFREE
of 5 and a PCTUSED
of 75, which is appropriate for a relatively static table. The definition also defines integrity constraints on some columns of the emp
table.
The following statement creates a temporary table flight_schedule
for use in an automated airline reservation scheduling system. Each client has its own session and can store temporary schedules. The temporary schedules are deleted at the end of the session.
CREATE GLOBAL TEMPORARY TABLE flight_schedule ( startdate DATE, enddate DATE, cost NUMBER) ON COMMIT PRESERVE ROWS;
To define the sample table salgrade
in the human_resource
tablespace with a small storage capacity and limited allocation potential, issue the following statement:
CREATE TABLE salgrade ( grade NUMBER CONSTRAINT pk_salgrade PRIMARY KEY USING INDEX TABLESPACE users_a, losal NUMBER, hisal NUMBER ) TABLESPACE human_resource STORAGE (INITIAL 6144 NEXT 6144 MINEXTENTS 1 MAXEXTENTS 5 );
The above statement also defines a primary key constraint on the grade
column and specifies that the index Oracle creates to enforce this constraint is created in the users_a
tablespace.
PARALLEL
Example
The following statement creates a table using an optimum number of parallel execution servers to scan scott
.emp
and to populate emp_dept
:
CREATE TABLE emp_dept PARALLEL AS SELECT * FROM scott.emp WHERE deptno = 10;
Using parallelism speeds up the creation of the table because Oracle uses parallel execution servers to create the table. After the table is created, querying the table is also faster, because the same degree of parallelism is used to access the table.
NOPARALLEL
Example
The following statement creates a table serially. Subsequent DML and queries on the table will also be serially executed.
CREATE TABLE emp_dept AS SELECT * FROM scott.emp WHERE deptno = 10;
ENABLE
VALIDATE
Example
The following statement creates the dept
table, defines a primary key constraint, and places it in ENABLE
VALIDATE
state:
CREATE TABLE dept (deptno NUMBER (2) PRIMARY KEY, dname VARCHAR2(10), loc VARCHAR2(9) ) TABLESPACE user_a;
DISABLE
Example
The following statement creates the dept
table and defines a disabled primary key constraint:
CREATE TABLE dept (deptno NUMBER (2) PRIMARY KEY DISABLE, dname VARCHAR2(10), loc VARCHAR2(9) );
EXCEPTIONS
INTO
Example
The following example creates the order_exceptions
table to hold rows from an index-organized table orders
that violate integrity constraint check_orders
:
CREATE TABLE orders (ord_num NUMBER PRIMARY KEY, ord_quantity NUMBER) ORGANIZATION INDEX; EXECUTE DBMS_IOT.BUILD_EXCEPTIONS_TABLE ('SCOTT', 'ORDERS', 'ORDER_EXCEPTIONS'); ALTER TABLE orders ADD CONSTRAINT CHECK_ORDERS CHECK (ord_quantity > 0) EXCEPTIONS INTO ORDER_EXCEPTIONS;
To specify an exception table, you must have the privileges necessary to insert rows into the table. To examine the identified exceptions, you must have the privileges necessary to query the exceptions table.
See Also:
|
The following statement creates relational table employee
with a nested table column projects
:
CREATE TABLE employee (empno NUMBER, name CHAR(31), projects PROJ_TABLE_TYPE) NESTED TABLE projects STORE AS nested_proj_table( (PRIMARY KEY (nested_table_id, pno)) ORGANIZATION INDEX) RETURN AS LOCATOR;
The following statement creates table lob_tab
with two LOB columns and specifies the LOB storage characteristics:
CREATE TABLE lob_tab (col1 BLOB, col2 CLOB) STORAGE (INITIAL 256 NEXT 256) LOB (col1, col2) STORE AS (TABLESPACE lob_seg_ts STORAGE (INITIAL 6144 NEXT 6144) CHUNK 4000 NOCACHE LOGGING);
In the example, Oracle rounds the value of CHUNK
up to 4096 (the nearest multiple of the block size of 2048).
The following statement creates an index-organized table:
CREATE TABLE docindex ( token CHAR(20), doc_oid INTEGER, token_frequency SMALLINT, token_occurrence_data VARCHAR2(512), CONSTRAINT pk_docindex PRIMARY KEY (token, doc_oid) ) ORGANIZATION INDEX TABLESPACE text_collection PCTTHRESHOLD 20 INCLUDING token_frequency OVERFLOW TABLESPACE text_collection_overflow;
The following statement creates a table with three partitions:
CREATE TABLE stock_xactions (stock_symbol CHAR(5), stock_series CHAR(1), num_shares NUMBER(10), price NUMBER(5,2), trade_date DATE) STORAGE (INITIAL 100K NEXT 50K) LOGGING PARTITION BY RANGE (trade_date) (PARTITION sx1992 VALUES LESS THAN (TO_DATE('01-JAN-1993','DD-MON-YYYY')) TABLESPACE ts0 NOLOGGING, PARTITION sx1993 VALUES LESS THAN (TO_DATE('01-JAN-1994','DD-MON-YYYY')) TABLESPACE ts1, PARTITION sx1994 VALUES LESS THAN (TO_DATE('01-JAN-1995','DD-MON-YYYY')) TABLESPACE ts2);
See Also:
Oracle8i Administrator's Guide for information about partitioned table maintenance operations |
This statement creates a partitioned table pt
with two partitions p1 and p2
, and three LOB columns, b
, c
, and d
:
CREATE TABLE PT (A NUMBER, B BLOB, C CLOB, D CLOB) LOB (B,C,D) STORE AS (STORAGE (NEXT 20M)) PARTITION BY RANGE (A) (PARTITION P1 VALUES LESS THAN (10) TABLESPACE TS1 LOB (B,D) STORE AS (TABLESPACE TSA STORAGE (INITIAL 20M)), PARTITION P2 VALUES LESS THAN (20) LOB (B,C) STORE AS (TABLESPACE TSB) TABLESPACE TSX;
Partition p1 will be in tablespace ts1
. The LOB data partitions for b
and d
will be in tablespace tsa
. The LOB data partition for c
will be in tablespace ts1
. The storage attribute INITIAL
is specified for LOB columns b
and d
; other attributes will be inherited from the default table-level specification. The default LOB storage attributes not specified at the table level will be inherited from the tablespace tsa
for columns b
and d
and tablespace ts1
for column c
. LOB index partitions will be in the same tablespaces as the corresponding LOB data partitions. Other storage attributes will be based on values of the corresponding attributes of the LOB data partitions and default attributes of the tablespace where the index partitions reside.
Partition p2
will be in the default tablespace tsx
. The LOB data for b
and c
will be in tablespace tsb
. The LOB data for d
will be in tablespace tsx
. The LOB index for columns b
and c
will be in tablespace tsb
. The LOB index for column d
will be in tablespace tsx
.
This statement creates a table partitioned by hash on columns containing data about chemicals. The hash partitions are stored in tablespaces tbs1
, tbs2
, tbs3
, and tbs4
:
CREATE TABLE exp_data ( d DATE, temperature NUMBER, Fe2O3_concentration NUMBER, HCl_concentration NUMBER, Au_concentration NUMBER, amps NUMBER, observation VARCHAR(4000)) PARTITION BY HASH (HCl_concentration, Au_concentration) PARTITIONS 32 STORE IN (tbs1, tbs2, tbs3, tbs4);
This statement creates a composite-partitioned table. The range partitioning facilitates data and partition pruning by sale date. The hash subpartitioning enables subpartition elimination for queries by a specific item number. Most of the partitions consist of 8 subpartitions. However, the partition covering the slowest quarter will have 4 subpartitions, and the partition covering the busiest quarter will have 16 subpartitions.
CREATE TABLE sales (item INTEGER, qty INTEGER, store VARCHAR(30), dept NUMBER, sale_date DATE) PARTITION BY RANGE (sale_date) SUBPARTITION BY HASH(item) SUBPARTITIONS 8 STORE IN (tbs1, tbs2, tbs3, tbs4, tbs5, tbs6, tbs7, tbs8) (PARTITION q1_1997 VALUES LESS THAN (TO_DATE('01-apr-1997', 'dd-mon-yyyy')), PARTITION q2_1997 VALUES LESS THAN (TO_DATE('01-jul-1997', 'dd-mon-yyyy')), PARTITION q3_1997 VALUES LESS THAN (TO_DATE('01-oct-1997', 'dd-mon-yyyy')) (SUBPARTITION q3_1997_s1 TABLESPACE ts1, SUBPARTITION q3_1997_s2 TABLESPACE ts3, SUBPARTITION q3_1997_s3 TABLESPACE ts5, SUBPARTITION q3_1997_s4 TABLESPACE ts7), PARTITION q4_1997 VALUES LESS THAN (TO_DATE('01-jan-1998', 'dd-mon-yyyy')) SUBPARTITIONS 16 STORE IN (tbs1, tbs3, tbs5, tbs7, tbs8, tbs9, tbs10, tbs11), PARTITION q1_1998 VALUES LESS THAN (TO_DATE('01-apr-1998', 'dd-mon-yyyy')));
Consider object type dept_t
:
CREATE TYPE dept_t AS OBJECT ( dname VARCHAR2(100), address VARCHAR2(200) );
Object table dept holds department objects of type dept_t
:
CREATE TABLE dept OF dept_t;
The following statement creates object table salesreps
with a user-defined object type, salesrep_t
:
CREATE OR REPLACE TYPE salesrep_t AS OBJECT ( repId NUMBER, repName VARCHAR2(64)); CREATE TABLE salesreps OF salesrep_t;
The following statement creates relational table employee
with a nested table column projects
:
CREATE TABLE employee (empno NUMBER, name CHAR(31), projects PROJ_TABLE_TYPE) NESTED TABLE projects STORE AS nested_proj_table;
REF
Example
The following example creates object type dept_t
and object table dept
to store instances of all departments. A table with a scoped REF
is then created.
CREATE TYPE dept_t AS OBJECT ( dname VARCHAR2(100), address VARCHAR2(200) ); CREATE TABLE dept OF dept_t; CREATE TABLE emp ( ename VARCHAR2(100), enumber NUMBER, edept REF dept_t SCOPE IS dept );
The following statement creates a table with a REF
column which has a referential constraint defined on it:
CREATE TABLE emp ( ename VARCHAR2(100), enumber NUMBER, edept REF dept_t REFERENCES dept);
This example creates an object type and a corresponding object table whose OID is primary key based:
CREATE TYPE emp_t AS OBJECT (empno NUMBER, address CHAR(30)); CREATE TABLE emp OF emp_t (empno PRIMARY KEY) OBJECT IDENTIFIER IS PRIMARY KEY;
You can subsequently reference the emp
object table in either of the following two ways:
CREATE TABLE dept (dno NUMBER mgr_ref REF emp_t SCOPE IS emp); CREATE TABLE dept ( dno NUMBER, mgr_ref REF emp_t CONSTRAINT mgr_in_emp REFERENCES emp);
CREATE TYPE address AS OBJECT ( hno NUMBER, street VARCHAR2(40), city VARCHAR2(20), zip VARCHAR2(5), phone VARCHAR2(10) ); CREATE TYPE person AS OBJECT ( name VARCHAR2(40), dateofbirth DATE, homeaddress address, manager REF person ); CREATE TABLE persons OF person ( homeaddress NOT NULL UNIQUE (homeaddress.phone), CHECK (homeaddress.zip IS NOT NULL), CHECK (homeaddress.city <> 'San Francisco') );
PARALLEL
Example
The following statement creates a table using 10 parallel execution servers, 5 to scan scott.emp
and another 5 to populate emp_dept
:
CREATE TABLE emp_dept PARALLEL (5) AS SELECT * FROM scott.emp WHERE deptno = 10;
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|