Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

ALTER VIEW

ALTER VIEW

Purpose

Use the ALTER VIEW statement to explicitly recompile a view that is invalid. Explicit recompilation lets you locate recompilation errors before run time. You may want to recompile a view explicitly after altering one of its base tables to ensure that the alteration does not affect the view or other objects that depend on it.

You can also use ALTER VIEW to define, modify, or drop view constraints.

When you issue an ALTER VIEW statement, Oracle recompiles the view regardless of whether it is valid or invalid. Oracle also invalidates any local objects that depend on the view.

Notes:

This statement does not change the definition of an existing view. To redefine a view, you must use CREATE VIEW with the

OR REPLACE keywords.

If you alter a view that is referenced by one or more materialized views, then those materialized views are invalidated. Invalid materialized views cannot be used by query rewrite and cannot be refreshed.

See Also:

CREATE VIEW on page 16-39 for information on redefining a view

ALTER MATERIALIZED VIEW on page 9-90 for information on revalidating an invalid materialized view

Oracle9i Data Warehousing Guide for general information on data warehouses

Oracle9i Database Concepts for more about dependencies among schema objects

SQL Statements: ALTER TRIGGER to COMMIT 12-31

ALTER VIEW

Prerequisites

The view must be in your own schema or you must have ALTER ANY TABLE system privilege.

Syntax

alter_view::=

 

 

ADD

out_of_line_constraint

 

 

 

 

 

 

 

RELY

 

 

MODIFY

CONSTRAINT

 

constraint

 

 

 

 

 

 

 

NORELY

 

schema

.

CONSTRAINT

constraint

 

ALTER

VIEW

view

 

 

 

;

 

 

 

PRIMARY

 

KEY

 

 

 

DROP

 

 

 

 

 

 

 

 

 

,

 

 

 

 

UNIQUE

(

column

)

 

 

COMPILE

 

 

 

(out_of_line_constraint::= on page 7-7—part of constraints syntax)

Semantics

schema

Specify the schema containing the view. If you omit schema, then Oracle assumes the view is in your own schema.

view

Specify the name of the view to be recompiled.

ADD Clause

Use the ADD clause to add a constraint to view.

See Also: constraints on page 7-5 for information on view constraints and their restrictions

12-32 Oracle9i SQL Reference

ALTER VIEW

MODIFY CONSTRAINT Clause

Use the MODIFY CONSTRAINT clause to change the RELY or NORELY setting of an existing view constraint.

Restriction on Modifying Constraints You cannot change the setting of a unique or primary key constraint if it is part of a referential integrity constraint without dropping the foreign key or changing its setting to match that of view.

See Also: "RELY Clause" on page 7-22 for information on the uses of the RELY and NORELY settings

DROP Clause

Use the DROP clause to drop an existing view constraint.

Restriction on Dropping Constraints You cannot drop a unique or primary key constraint if it is part of a referential integrity constraint on a view.

COMPILE

The COMPILE keyword is required. It directs Oracle to recompile the view.

Example

Altering a View: Example To recompile the view customer_ro (created in "Creating a Read-Only View: Example" on page 16-52), issue the following statement:

ALTER VIEW customer_ro

COMPILE;

If Oracle encounters no compilation errors while recompiling customer_ro, then customer_ro becomes valid. If recompiling results in compilation errors, then Oracle returns an error and customer_ro remains invalid.

Oracle also invalidates all dependent objects. These objects include any procedures, functions, package bodies, and views that reference customer_ro. If you subsequently reference one of these objects without first explicitly recompiling it, then Oracle recompiles it implicitly at run time.

SQL Statements: ALTER TRIGGER to COMMIT 12-33

ANALYZE

ANALYZE

Purpose

Use the ANALYZE statement to collect non-optimizer statistics, for example, to:

Collect or delete statistics about an index or index partition, table or table partition, index-organized table, cluster, or scalar object attribute.

Validate the structure of an index or index partition, table or table partition, index-organized table, cluster, or object reference (REF).

Identify migrated and chained rows of a table or cluster.

Note: Oracle Corporation strongly recommends that you use the DBMS_STATS package rather than ANALYZE to collect optimizer statistics. That package lets you collect statistics in parallel, collect global statistics for partitioned objects, and fine tune your statistics collection in other ways. Further, the cost-based optimizer, which depends upon statistics, will eventually use only statistics that have been collected by DBMS_STATS. See Oracle9i Supplied PL/SQL Packages and Types Reference for more information on this package.

However, you must use the ANALYZE statement (rather than DBMS_ STATS) for statistics collection not related to the cost-based optimizer, such as:

To use the VALIDATE or LIST CHAINED ROWS clauses

To collect information on freelist blocks

Prerequisites

The schema object to be analyzed must be local, and it must be in your own schema or you must have the ANALYZE ANY system privilege.

If you want to list chained rows of a table or cluster into a list table, then the list table must be in your own schema, or you must have INSERT privilege on the list table, or you must have INSERT ANY TABLE system privilege.

If you want to validate a partitioned table, then you must have INSERT privilege on the table into which you list analyzed rowids, or you must have INSERT ANY TABLE system privilege.

12-34 Oracle9i SQL Reference

ANALYZE

Syntax

analyze::=

 

 

 

PARTITION

(

 

partition

)

 

 

schema

.

SUBPARTITION

 

(

subpartition

)

 

TABLE

 

table

 

 

 

 

 

 

 

 

PARTITION

(

 

partition

)

 

ANALYZE

schema

.

SUBPARTITION

 

(

subpartition

)

 

INDEX

 

index

 

 

 

 

 

 

schema

 

.

 

 

 

 

 

 

CLUSTER

 

cluster

 

 

 

 

 

compute_statistics_clause estimate_statistics_clause validation_clauses

;

 

 

into_clause

LIST

CHAINED

ROWS

 

SYSTEM

DELETE

 

STATISTICS

compute_statistics_clause::=

SYSTEM

for_clause

COMPUTE

STATISTICS

estimate_statistics_clause::=

 

SYSTEM

for_clause

ESTIMATE

 

STATISTICS

 

 

ROWS

SAMPLE

integer

 

 

 

PERCENT

SQL Statements: ALTER TRIGGER to COMMIT 12-35

ANALYZE

validation_clauses::=

SET DANGLING TO NULL

VALIDATE REF UPDATE

CASCADE

into_clause

OFFLINE

VALIDATE STRUCTURE

ONLINE

for_clause::=

 

TABLE

 

 

 

 

 

INDEXED

 

SIZE

integer

 

 

ALL

COLUMNS

 

 

 

FOR

SIZE

integer

column

SIZE

integer

 

COLUMNS

 

 

 

 

 

 

 

attribute

 

 

 

LOCAL

 

 

 

 

 

ALL

INDEXES

 

 

 

into_clause::=

schema .

INTO

table

Semantics

schema

Specify the schema containing the index, table, or cluster. If you omit schema, then Oracle assumes the index, table, or cluster is in your own schema.

INDEX index

Specify an index to be analyzed (if no for_clause is used).

Oracle collects the following statistics for an index. Statistics marked with an asterisk are always computed exactly. For conventional indexes, the statistics appear in the data dictionary views USER_INDEXES, ALL_INDEXES, and DBA_ INDEXES in the columns in parentheses.

12-36 Oracle9i SQL Reference

ANALYZE

*Depth of the index from its root block to its leaf blocks (BLEVEL)

Number of leaf blocks (LEAF_BLOCKS)

Number of distinct index values (DISTINCT_KEYS)

Average number of leaf blocks for each index value (AVG_LEAF_BLOCKS_PER_ KEY)

Average number of data blocks for each index value (for an index on a table) (AVG_DATA_BLOCKS_PER_KEY)

Clustering factor (how well ordered the rows are about the indexed values) (CLUSTERING_FACTOR)

For domain indexes, this statement invokes the user-defined statistics collection function specified in the statistics type associated with the index (see ASSOCIATE STATISTICS on page 12-50). If no statistics type is associated with the domain index, then the statistics type associated with its indextype is used. If no statistics type exists for either the index or its indextype, then no user-defined statistics are collected. User-defined index statistics appear in the STATISTICS column of the data dictionary views USER_USTATS, ALL_USTATS, and DBA_USTATS.

Restriction on Analyzing Indexes You cannot analyze a domain index that is marked IN_PROGRESS or FAILED.

See Also:

CREATE INDEX on page 13-65 for more information on domain indexes

Oracle9i Database Reference for information on the data dictionary views

"Analyzing an Index: Example" on page 12-48

TABLE table

Specify a table to be analyzed. When you collect statistics for a table, Oracle also automatically collects the statistics for each of the table’s indexes and domain indexes, as long as no for_clauses are used.

When you analyze a table, Oracle collects statistics about expressions occurring in any function-based indexes as well. Therefore, be sure to create function-based indexes on the table before analyzing the table.

SQL Statements: ALTER TRIGGER to COMMIT 12-37

ANALYZE

See Also: CREATE INDEX on page 13-65 for more information about function-based indexes

When analyzing a table, Oracle skips all domain indexes marked LOADING or

FAILED.

For an index-organized table, Oracle also analyzes any mapping table and calculates its PCT_ACCESSS_DIRECT statistics. These statistics estimate the accuracy of "guess" data block addresses stored as part of the local rowids in the mapping table.

Oracle collects the following statistics for a table. Statistics marked with an asterisk are always computed exactly. Table statistics, including the status of domain indexes, appear in the data dictionary views USER_TABLES, ALL_TABLES, and DBA_TABLES in the columns shown in parentheses.

Number of rows (NUM_ROWS)

* Number of data blocks below the high water mark (that is, the number of data blocks that have been formatted to receive data, regardless whether they currently contain data or are empty) (BLOCKS)

* Number of data blocks allocated to the table that have never been used (EMPTY_BLOCKS)

Average available free space in each data block in bytes (AVG_SPACE)

Number of chained rows (CHAIN_COUNT)

Average row length, including the row’s overhead, in bytes (AVG_ROW_LEN)

Restrictions on Analyzing Tables

You cannot use ANALYZE to collect statistics on data dictionary tables.

You cannot use ANALYZE to collect statistics on an external table. However, you can use the DBMS_STATS package for this purpose.

You cannot use ANALYZE to collect default statistics on a temporary table. However, if you have created an association between one or more columns of a temporary table and a user-defined statistics type, then you can use ANALYZE to collect the user-defined statistics on the temporary table. (The association must already exist.)

You cannot compute or estimate statistics for the following column types: REFs, varrays, nested tables, LOBs (LOBs are not analyzed, they are skipped), LONGs,

12-38 Oracle9i SQL Reference

ANALYZE

or object types. However, if a statistics type is associated with such a column, then user-defined statistics are collected.

See Also:

ASSOCIATE STATISTICS on page 12-50

Oracle9i Database Reference for information on the data dictionary views

PARTITION | SUBPARTITION

Specify the partition or subpartition on which you want statistics to be gathered. You cannot use this clause when analyzing clusters.

If you specify PARTITION and table is composite-partitioned, then Oracle analyzes all the subpartitions within the specified partition.

CLUSTER cluster

Specify a cluster to be analyzed. When you collect statistics for a cluster, Oracle also automatically collects the statistics for all the cluster’s tables and all their indexes, including the cluster index.

For both indexed and hash clusters, Oracle collects the average number of data blocks taken up by a single cluster key (AVG_BLOCKS_PER_KEY). These statistics appear in the data dictionary views ALL_CLUSTERS, USER_CLUSTERS and DBA_ CLUSTERS.

See Also: Oracle9i Database Reference for information on the data dictionary views and "Analyzing a Cluster: Example" on page 12-48

compute_statistics_clause

COMPUTE STATISTICS instructs Oracle to compute exact statistics about the analyzed object and store them in the data dictionary. When you analyze a table, both table and column statistics are collected.

Both computed and estimated statistics are used by the Oracle optimizer to choose the execution plan for SQL statements that access analyzed objects. These statistics may also be useful to application developers who write such statements.

Specify SYSTEM if you want Oracle to compute only system (not user-defined statistics). If you omit SYSTEM, then Oracle collects both system-generated statistics and statistics generated by the collection functions declared in a statistics type.

SQL Statements: ALTER TRIGGER to COMMIT 12-39

ANALYZE

See Also:

Oracle9i Data Cartridge Developer’s Guide for information on creating statistics collection functions

Oracle9i Database Performance Tuning Guide and Reference for information on how these statistics are used

"Computing Statistics: Examples" on page 12-47

for_clause

The for_clause lets you specify whether an entire table or index, or just particular columns, will be analyzed. The following clauses apply only to the ANALYZE TABLE version of this statement.

FOR TABLE Specify FOR TABLE to restrict the statistics collected to only table statistics rather than table and column statistics.

FOR COLUMNS Specify FOR COLUMNS to restrict the statistics collected to only column statistics for the specified columns and scalar object attributes, rather than for all columns and attributes; attribute specifies the qualified column name of an item in an object.

FOR ALL COLUMNS Specify FOR ALL COLUMNS to collect column statistics for all columns and scalar object attributes.

FOR ALL INDEXED COLUMNS Specify FOR ALL INDEXED COLUMNS to collect column statistics for all indexed columns in the table.

Column statistics can be based on the entire column or can use a histogram by specifying SIZE.

Oracle collects the following column statistics:

Number of distinct values in the column as a whole

Maximum and minimum values in each band

See Also: Oracle9i Database Performance Tuning Guide and Reference and "Creating Histograms: Examples" on page 12-47 for more information on histograms

Column statistics appear in the data dictionary views USER_TAB_COLUMNS, ALL_ TAB_COLUMNS, and DBA_TAB_COLUMNS. Histograms appear in the data dictionary

12-40 Oracle9i SQL Reference

ANALYZE

views USER_TAB_HISTOGRAMS, DBA_TAB_HISTOGRAMS, and ALL_TAB_ HISTOGRAMS; USER_PART_HISTOGRAMS, DBA_PART_HISTOGRAMS, and ALL_ PART_HISTOGRAMS; and USER_SUBPART_HISTOGRAMS, DBA_SUBPART_ HISTOGRAMS, and ALL_SUBPART_HISTOGRAMS.

Note: MAXVALUE and MINVALUE columns of USER_, DBA_, and

ALL_TAB_COLUMNS have a length of 32 bytes. If you analyze columns with a length >32 bytes, and if the columns are padded with leading blanks, then Oracle may take into account only the leading blanks and return unexpected statistics.

If a user-defined statistics type has been associated with any columns, then the for_clause collects user-defined statistics using that statistics type. If no statistics type is associated with a column, then Oracle checks to see if any statistics type has been associated with the type of the column, and uses that statistics type. If no statistics type has been associated with either the column or its user-defined type, then no user-defined statistics are collected. User-defined column statistics appear in the STATISTICS column of the data dictionary views USER_USTATS, ALL_ USTATS, and DBA_USTATS.

If you want to collect statistics on both the table as a whole and on one or more columns, then be sure to generate the statistics for the table first, and then for the columns. Otherwise, the table-only ANALYZE will overwrite the histograms generated by the column ANALYZE. For example, issue the following statements:

ANALYZE TABLE emp ESTIMATE STATISTICS;

ANALYZE TABLE emp ESTIMATE STATISTICS

FOR ALL COLUMNS;

FOR ALL INDEXES Specify FOR ALL INDEXES if you want all indexes associated with the table to be analyzed.

FOR ALL LOCAL INDEXES Specify FOR ALL LOCAL INDEXES if you want all local index partitions to be analyzed. You must specify the keyword LOCAL if the PARTITION clause and INDEX are specified.

SIZE Specify the maximum number of buckets in the histogram. The default value is 75, minimum value is 1, and maximum value is 254.

SQL Statements: ALTER TRIGGER to COMMIT 12-41

ANALYZE

Note: Oracle does not create a histogram with more buckets than the number of rows in the sample. Also, if the sample contains any values that are very repetitious, then Oracle creates the specified number of buckets, but the value indicated by the NUM_BUCKETS column of the ALL_, DBA_, and USER_TAB_COLUMNS views may be smaller because of an internal compression algorithm.

See Also: "Creating Histograms: Examples" on page 12-47

estimate_statistics_clause

ESTIMATE STATISTICS instructs Oracle to estimate statistics about the analyzed object and store them in the data dictionary.

Both computed and estimated statistics are used by the Oracle optimizer to choose the execution plan for SQL statements that access analyzed objects. These statistics may also be useful to application developers who write such statements.

Specify SYSTEM if you want Oracle to estimate only system (not user-defined statistics). If you omit SYSTEM, then Oracle estimates both system-generated statistics and statistics generated by the collection functions declared in a statistics type.

See Also: Oracle9i Data Cartridge Developer’s Guide for information on creating statistics collection functions and "Estimating Statistics: Example" on page 12-47

for_clause See the description under compute_statistics_clause on page 12-39

SAMPLE Specify the amount of data from the analyzed object Oracle should sample to estimate statistics. If you omit this parameter, then Oracle samples 1064 rows.

The default sample value is adequate for tables up to a few thousand rows. If your tables are larger, specify a higher value for SAMPLE. If you specify more than half of the data, then Oracle reads all the data and computes the statistics.

ROWS causes Oracle to sample integer rows of the table or cluster or integer entries from the index. The integer must be at least 1.

12-42 Oracle9i SQL Reference

ANALYZE

PERCENT causes Oracle to sample integer percent of the rows from the table or cluster or integer percent of the index entries. The integer can range from 1 to 99.

See Also: Oracle9i Database Performance Tuning Guide and Reference for information on how these statistics are used

validation_clauses

The validation clauses let you validate REFs and the structure of the analyzed object.

VALIDATE REF UPDATE Clause

Specify VALIDATE REF UPDATE to validate the REFs in the specified table, check the rowid portion in each REF, compare it with the true rowid, and correct, if necessary. You can use this clause only when analyzing a table.

SET DANGLING TO NULL SET DANGLING TO NULL sets to NULL any REFs

(whether or not scoped) in the specified table that are found to point to an invalid or nonexistent object.

Note: If the owner of the table does not have SELECT object privilege on the referenced objects, then Oracle will consider them invalid and set them to NULL. Subsequently these REFs will not be available in a query, even if it is issued by a user with appropriate privileges on the objects.

VALIDATE STRUCTURE

Specify VALIDATE STRUCTURE to validate the structure of the analyzed object. The statistics collected by this clause are not used by the Oracle optimizer, as are statistics collected by the COMPUTE STATISTICS and ESTIMATE STATISTICS clauses.

See Also: "Validating a Table: Example" on page 12-48

For a table, Oracle verifies the integrity of each of the table’s data blocks and rows. For an index-organized table, Oracle also generates compression statistics (optimal prefix compression count) for the primary key index on the table.

For a cluster, Oracle automatically validates the structure of the cluster’s tables.

SQL Statements: ALTER TRIGGER to COMMIT 12-43

ANALYZE

For a partitioned table, Oracle also verifies that each row belongs to the correct partition. If a row does not collate correctly, then its rowid is inserted into the

INVALID_ROWS table.

For a temporary table, Oracle validates the structure of the table and its indexes during the current session.

For an index, Oracle verifies the integrity of each data block in the index and checks for block corruption. This clause does not confirm that each row in the table has an index entry or that each index entry points to a row in the table.

You can perform these operations by validating the structure of the table with the CASCADE clause.

Oracle also computes compression statistics (optimal prefix compression count) for all normal indexes

Oracle stores statistics about the index in the data dictionary views INDEX_ STATS and INDEX_HISTOGRAM.

See Also: Oracle9i Database Reference for information on these views

If Oracle encounters corruption in the structure of the object, then an error message is returned to you. In this case, drop and re-create the object.

INTO The INTO clause of VALIDATE STRUCTURE is valid only for partitioned tables. Specify a table into which Oracle lists the rowids of the partitions whose rows do not collate correctly. If you omit schema, then Oracle assumes the list is in your own schema. If you omit this clause altogether, then Oracle assumes that the table is named INVALID_ROWS. The SQL script used to create this table is

UTLVALID.SQL.

CASCADE Specify CASCADE if you want Oracle to validate the structure of the indexes associated with the table or cluster. If you use this clause when validating a table, then Oracle also validates the table’s indexes. If you use this clause when validating a cluster, then Oracle also validates all the clustered tables’ indexes, including the cluster index.

If you use this clause to validate an enabled (but previously disabled) function-based index, then validation errors may result. In this case, you must rebuild the index.

12-44 Oracle9i SQL Reference

ANALYZE

ONLINE | OFFLINE Specify ONLINE to enable Oracle to run the validation while DML operations are ongoing within the object. Oracle reduces the amount of validation performed to allow for concurrency.

Note: When you validate the structure of an object ONLINE, Oracle does not collect any statistics, as it does when you validate the structure of the object OFFLINE.

Specify OFFLINE, to maximize the amount of validation performed. This setting prevents INSERT, UPDATE, and DELETE statements from concurrently accessing the object during validation but allows queries. This is the default.

Restriction on ONLINE You cannot specify ONLINE when analyzing a clustered object.

LIST CHAINED ROWS

LIST CHAINED ROWS lets you identify migrated and chained rows of the analyzed table or cluster. You cannot use this clause when analyzing an index.

In the INTO clause, specify a table into which Oracle lists the migrated and chained rows. If you omit schema, then Oracle assumes the list table is in your own schema. If you omit this clause altogether, then Oracle assumes that the table is named CHAINED_ROWS. The list table must be on your local database.

You can create the CHAINED_ROWS table using one of these scripts:

UTLCHAIN.SQL uses physical rowids. Therefore it can accommodate rows from conventional tables but not from index-organized tables. (See the Note that follows.)

UTLCHN1.SQL uses universal rowids, so it can accommodate rows from both conventional and index-organized tables.

If you create your own chained-rows table, then it must follow the format prescribed by one of these two scripts.

SQL Statements: ALTER TRIGGER to COMMIT 12-45

ANALYZE

Note: If you are analyzing index-organized tables based on primary keys (rather than universal rowids), then you must create a separate chained-rows table for each index-organized table to accommodate its primary-key storage. Use the SQL scripts

DBMSIOTC.SQL and PRVTIOTC.PLB to define the BUILD_CHAIN_ ROWS_TABLE procedure, and then execute this procedure to create an IOT_CHAINED_ROWS table for each such index-organized table.

See Also:

Oracle9i Database Migration Guide for compatibility issues related to the use of the UTL* scripts

The DBMS_IOT package in Oracle9i Supplied PL/SQL Packages and Types Reference for information on the packaged SQL scripts

Oracle9i Database Administrator’s Guide for information on eliminating migrated and chained rows

"Listing Chained Rows: Example" on page 12-48

DELETE STATISTICS

Specify DELETE STATISTICS to delete any statistics about the analyzed object that are currently stored in the data dictionary. Use this statement when you no longer want Oracle to use the statistics.

When you use this clause on a table, Oracle also automatically removes statistics for all the table’s indexes. When you use this clause on a cluster, Oracle also automatically removes statistics for all the cluster’s tables and all their indexes, including the cluster index.

Specify SYSTEM if you want Oracle to delete only system (not user-defined statistics). If you omit SYSTEM, and if user-defined column or index statistics were collected for an object, then Oracle also removes the user-defined statistics by invoking the statistics deletion function specified in the statistics type that was used to collect the statistics.

See Also: "Deleting Statistics: Example" on page 12-47

12-46 Oracle9i SQL Reference

ANALYZE

Examples

Computing Statistics: Examples The following statement computes statistics for the sample table oe.orders:

ANALYZE TABLE orders COMPUTE STATISTICS;

The following statement computes only system statistics on the sample table oe.orders:

ANALYZE TABLE orders COMPUTE SYSTEM STATISTICS;

The following statement calculates statistics for a scalar object attribute: ANALYZE TABLE customers COMPUTE STATISTICS

FOR COLUMNS cust_address.postal_code;

Estimating Statistics: Example The following statement estimates statistics for the sample table oe.orders and all of its indexes:

ANALYZE TABLE orders ESTIMATE STATISTICS;

Deleting Statistics: Example The following statement deletes statistics about the sample table oe.orders and all its indexes from the data dictionary:

ANALYZE TABLE orders DELETE STATISTICS;

Creating Histograms: Examples The following statement creates a 10-band histogram on the location_id column of the sample table hr.locations:

ANALYZE TABLE locations

COMPUTE STATISTICS FOR COLUMNS country_id SIZE 10;

You can then query the USER_TAB_COLUMNS data dictionary view to retrieve statistics:

SELECT NUM_DISTINCT, NUM_BUCKETS, SAMPLE_SIZE FROM USER_TAB_COLUMNS

WHERE TABLE_NAME = ’LOCATIONS’ AND COLUMN_NAME = ’COUNTRY_ID’;

NUM_DISTINCT NUM_BUCKETS SAMPLE_SIZE

------------

-----------

-----------

14

7

23

Depending on the size of your table, even though the ANALYZE statement specified 10 buckets, Oracle may create fewer buckets that you specify in the ANALYZE statement. For an explanation, see the note on SIZE on page 12-41.

SQL Statements: ALTER TRIGGER to COMMIT 12-47

ANALYZE

You can also collect histograms for a single partition of a table. The following statement analyzes partition sales_q2_2000 of the sample table sh.sales:

ANALYZE TABLE sales PARTITION (sales_q2_2000) COMPUTE STATISTICS;

Analyzing an Index: Example The following statement validates the structure of the sample index oe.inv_product_ix:

ANALYZE INDEX inv_product_ix VALIDATE STRUCTURE;

Validating a Table: Example The following statement analyzes the sample table hr.employees and all of its indexes:

ANALYZE TABLE employees VALIDATE STRUCTURE CASCADE;

For a table, the VALIDATE REF UPDATE clause verifies the REFs in the specified table, checks the rowid portion of each REF, and then compares it with the true rowid. If the result is an incorrect rowid, then the REF is updated so that the rowid portion is correct.

The following statement validates the REFs in the sample table oe.customers:

ANALYZE TABLE customers VALIDATE REF UPDATE;

The following statements validates the structure of the sample table oe.customers while allowing simultaneous DML:

ANALYZE TABLE customers VALIDATE STRUCTURE ONLINE;

Analyzing a Cluster: Example The following statement analyzes the personnel cluster (created in "Creating a Cluster: Example" on page 13-9), all of its tables, and all of their indexes, including the cluster index:

ANALYZE CLUSTER personnel

VALIDATE STRUCTURE CASCADE;

Listing Chained Rows: Example The following statement collects information about all the chained rows of the table orders:

ANALYZE TABLE orders

LIST CHAINED ROWS INTO chained_rows;

The preceding statement places the information into the table chained_rows. You can then examine the rows with this query (no rows will be returned if the table contains no chained rows):

12-48 Oracle9i SQL Reference

ANALYZE

SELECT owner_name, table_name, head_rowid,

analyze_timestamp

 

FROM chained_rows;

 

 

OWNER_NAME TABLE_NAME

HEAD_ROWID

ANALYZE_TIMESTAMP

----------

----------

------------------

-----------------

OE

ORDERS

AAAAZzAABAAABrXAAA

25-SEP-2000

SQL Statements: ALTER TRIGGER to COMMIT 12-49

Соседние файлы в папке Oracle selected docs