1. Trang chủ
  2. » Công Nghệ Thông Tin

Oracle Database 10g The Complete Reference phần 9 pptx

135 344 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 135
Dung lượng 857,95 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

CREATE DATABASE SEE ALSO ALTER DATABASE, CREATE CONTROLFILE, CREATE ROLLBACK SEGMENT, CREATE TABLESPACE, SHUTDOWN, STARTUP, Chapters 2 and 46 MAXDATAFILES integer MAXINSTANCES integer CH

Trang 1

A condition is an expression whose value evaluates to either TRUE or FALSE, such as Age > 65

CONNECT (Form 1—SQL*Plus))

SEE ALSO COMMIT, DISCONNECT, Chapter 23

FORMAT

CON[NECT] [{user[/password] [@connect_identifier] |/} [AS SYSOPER|SYSDBA}]];

DESCRIPTION You must be in SQL*Plus to use this command, although you don’t need to be

logged onto Oracle (see DISCONNECT) CONNECT commits any pending changes, logs you off of

Oracle, and logs on as the specifieduser If the password is absent, you are prompted for it It is not

displayed when you type it in response to a prompt

@connect_identifier connects to the named database It may be on your host, or on another computerconnected via Oracle Net

CONNECT (Form 2—Embedded SQL)

SEE ALSO COMMIT, DECLARE DATABASE, Chapter 23

FORMAT

EXEC SQL CONNECT

{ :user IDENTIFIED BY :password | :user_password }

[AT { database | :host_variable}]

[USING :connect_string]

[ALTER AUTHORIZATION :new_password

| IN {SYSDBA | SYSOPER } MODE ]

DESCRIPTION CONNECT connects a host program to a local or remote database It may be used

more than once to connect to multiple databases :user_password is a host variable that contains the

Oracle username and password separated by a slash (/) Alternatively, :user and :password can be entered

separately by using the second format

AT is used to name a database other than the default for this user It is a required clause to reach

any databases other than the user’s default database This name can be used later in other SQL statements

with AT This database must be first identified with DECLARE DATABASE USING specifies an optional

Oracle Net string (such as a service name) used during the CONNECT operation Without the USING

string, you will be connected to the user’s default database, regardless of the database named in the

CONNECT BY [PRIOR] expression = [PRIOR] expression

START WITH expression = expression

ORDER BY expression

Trang 2

DESCRIPTION CONNECT BY is an operator used in a SELECT statement to create reports on

inheritance in tree-structured data, such as company organization, family trees, and so on START

WITH tells where in the tree to begin These are the rules:

The position of PRIOR with respect to the CONNECT BY expressions determines whichexpression identifies the root and which identifies the branches of the tree

A WHERE clause will eliminate individuals from the tree, but not their descendants (or ancestors,

depending on the location of PRIOR).

A qualification in the CONNECT BY (particularly a not equal sign instead of the equal sign)will eliminate both an individual and all of its descendants

CONNECT BY cannot be used with a table join in the WHERE clause.

EXAMPLE

select Cow, Bull, LPAD(' ',6*(Level-1))||Offspring AS Offspring,

Sex, Birthdatefrom BREEDING

connect by Offspring = PRIOR Cow

start with Offspring = 'DELLA'

order by Birthdate;

In this example, the following clause:

connect by Offspring = PRIOR Cow

means the offspring is the cow PRIOR to this one.

CONSTRAINT

A constraint is a rule or restriction concerning a piece of data (such as a NOT NULL restriction on a

column) that is enforced at the data level rather than at the object or application level.See INTEGRITY

Trang 3

PRIMARY KEY references_clause CHECK ( condition )

constraint_state

CONSTRAINT constraint_name

UNIQUE ( column

, )

PRIMARY KEY ( column

, )

FOREIGN KEY ( column

, ) references_clause CHECK ( condition )

constraint_state

SCOPE IS

schema

scope_table WITH ROWID

schema

scope_table

REF (

ref_col ref_attr ) WITH ROWID

CONSTRAINT constraint_name

FOREIGN KEY (

ref_col ref_attr ) references_clause

constraint_state

Trang 4

DISABLE VALIDATE NOVALIDATE RELY NORELY using_index_clause exceptions_clause

USING INDEX

schema

index ( create_index_statement ) index_properties

global_partitioned_index local_partitioned_index index_attributes domain_index_clause

REFERENCES

schema

object ( column )

ON DELETE

CASCADE SET NULL

Trang 5

exceptions_clause::=

DESCRIPTION Constraints are defined with the RELATIONAL_PROPERTIES clause of the CREATE

TABLE and ALTER TABLE commands You use the constraints clauses to create a constraint or to alter

an existing constraint You can enable and disable constraints If you disable a constraint and then try

to re-enable it, Oracle will check the data If the constraint cannot be re-enabled, Oracle can write the

exceptions out to a separate table for review

For PRIMARY KEY and UNIQUE constraints, Oracle creates indexes As part of the constraint clause for

those constraints, you can use the USING INDEX clause to specify the tablespace and storage for the index.

CONTAINS

CONTAINS is used to evaluate text searches that use CONTEXT indexes within Oracle Text.See

Chapter 25 Supported text search operators for CONTAINS are shown in the following table:

Operator Description

OR Returns a record if either search term has a score that exceeds the threshold.

AND Returns a record if both search terms have a score that exceeds the threshold.

ACCUM Returns a record if the sum of the search terms’ scores exceeds the threshold.

TABLESPACE

tablespace DEFAULT key_compression

SORT NOSORT REVERSE parallel_clause

Trang 6

Operator Description

MINUS Returns a record if the score of the first search minus the score of the second search exceeds

the threshold.

* Assigns different weights to the score of the searches.

NEAR The score will be based on how near the search terms are to each other in the searched text.

{} Encloses reserved words such as AND if they are part of the search term.

$ Performs stem expansion of the search term prior to performing the search.

? Performs a fuzzy match (allowing for misspellings) of the search term prior to performing

the search.

() Specifies the order in which search criteria are evaluated.

CONTEXT AREA

A context area is work area in memory where Oracle stores the current SQL statement and, if the statement

is a query, one row of the result The context area holds the state of a cursor

CONTEXT INDEX

Oracle Text supports three types of text indexes: CONTEXT indexes, CTXCAT indexes, and CTXRULE

indexes CONTEXT indexes use the CONTAINS operator and support a wider array of text search

capabilities CTXCAT indexes support a narrower set of search operators but support the creation of

index sets CTXRULE indexes are indexes on columns that contain a set of text queries.See Chapter 25

for details

CONTROL FILE (DATABASE)

A control file is a small administrative file that is required by every database to enable the database to

start and run a database system Multiple identical control files are created for redundancy

CONTROL FILE (SQL*LOADER)

A SQL*Loader control file tells the SQL*Loader executable where to find the data to be loaded, and

how to process the data during the load Every SQL*Loader session has an associated control file

For control file syntax, see SQLLDR For details on the use of SQL*Loader, see Chapter 21.

CONVERSION FUNCTIONS

Chapter 11

DESCRIPTION The following is an alphabetical list of all current conversion and transformation

functions in Oracle version of SQL

1068 Part IX: Alphabetical Reference

Trang 7

Function Name Definition

ASCIISTR Translates a string in any character set and returns an ASCII string in the database

character set.

BIN_TO_NUM Converts a binary value to its numerical equivalent.

CAST CASTs one built-in or collection type to another; commonly used with nested tables

and varying arrays.

CHARTOROWID Changes a character string to act like an internal Oracle row identifier, or ROWID.

COMPOSE Translates a string in any datatype to a Unicode string in its fully normalized form in the

same character set as the input.

CONVERT CONVERTs a character string from one national language character set to another.

DECOMPOSE Translates a string in any datatype to a Unicode string after canonical decomposition in

the same character set as the input.

HEXTORAW Changes a character string of hex numbers into binary.

NUMTODSINTERVAL Converts a NUMBER to an INTERVAL DAY TO SECOND literal.

NUMTOYMINTERVAL Converts a NUMBER to an INTERVAL YEAR TO MONTH literal.

RAWTOHEX Changes a string of binary numbers to a character string of hex numbers.

RAWTONHEX Converts RAW to an NVARCHAR2 character value containing its hexadecimal

equivalent.

ROWIDTOCHAR Changes an internal Oracle row identifier, or ROWID, to a character string.

ROWIDTONCHAR Converts a ROWID value to an NVARCHAR2 datatype.

SCN_TO_TIMESTAMP Converts a system change number to an approximate timestamp.

TIMESTAMP_TO_SCN Converts a timestamp to an approximate system change number.

TO_BINARY_DOUBLE Returns a double-precision floating-point number.

TO_BINARY_FLOAT Returns a single-precision floating-point number.

TO_CHAR Converts a NUMBER or DATE to a character string.

TO_CLOB Converts NCLOB values in a LOB column or other character strings to CLOB values.

TO_DATE Converts a NUMBER, CHAR, or VARCHAR2 to a DATE (an Oracle datatype).

TO_DSINTERVAL Converts a character string of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype

to an INTERVAL DAY TO SECOND type.

TO_LOB Converts a LONG to a LOB as part of an INSERT AS SELECT.

TO_MULTI_BYTE Converts the single-byte characters in a character string to multibyte characters.

TO_NCHAR Converts a character string, NUMBER, or DATE from the database character set to the

national character set.

TO_NCLOB Converts CLOB values in a LOB column or other character strings to NCLOB values.

TO_NUMBER Converts a CHAR or VARCHAR2 to a number.

TO_SINGLE_BYTE Converts the multibyte characters in a CHAR or VARCHAR2 to single bytes.

TO_TIMESTAMP Converts a character string to a value of TIMESTAMP datatype.

Trang 8

Function Name Definition

TO_TIMESTAMP_TZ Converts a character string to a value of TIMESTAMP WITH TIME ZONE datatype.

TO_YMINTERVAL Converts a character string of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype

to an INTERVAL YEAR TO MONTH type.

TRANSLATE…USING TRANSLATEs characters in a string into different characters.

UNISTR Converts a string into Unicode in the database Unicode character set.

CONVERT

FORMAT

CONVERT(string,[destination_set,[source_set]])

DESCRIPTION CONVERT is used to convert the characters instring from one standard bit

representation to another, such as from US7ASCII (the default if either set isn’t entered) to WE8DEC

This is typically done when data entered into a column on one computer contains characters that can’t

be properly displayed or printed on another computer CONVERT allows a reasonable translation of

one standard to the other in most cases The most common sets include:

US7ASCII Standard U.S 7-bit ASCII set

WE8DEC DEC’s 8-bit ASCII set for Western Europe

WE8ISO8859P1 ISO 8859-1 Western Europe 8-bit character set

command is likely to be made obsolete in a future release

SEE ALSO CREATE DATABASE LINK, Chapter 23

FORMAT

COPY [FROM user/password@database]

[TO user/password@database]

{APPEND | CREATE | INSERT | REPLACE}

table [ (column [,column] ) ]USING query

1070 Part IX: Alphabetical Reference

Trang 9

DESCRIPTION COPY copies FROM a table TO a table in another computer using Oracle Net.

FROM is the username, password, and database of the source table, and TO is the destination table.

Either FROM or TO may be omitted, in which case the user’s default database will be used for the

missing clause The source and destination databases must not be the same, so only one of the FROM

and TO clauses may be absent.

APPEND adds to the destination table; if the table does not exist, it is created CREATE requires

that the destination table be created; if it already exists, a 'table already exists' error occurs INSERT

adds to the destination table; if the table does not exist, a 'table does not exist' error occurs REPLACE

drops the data in the destination table and replaces it with the data from the source table; if the table

does not exist, it is created

table is the name of the destination table column is the name(s) of the column(s) in the destinationtable If named, the number of columns must be the same as in the query If no columns are named,

the copied columns will have the same names in the destination table as they had in the source table

query identifies the source table and determines which rows and columns will be copied from it

SET LONG ( see SET) determines the length of a long field that can be copied LONG columns with data longer than the value of LONG will be truncated SET COPYCOMMIT determines how many sets

of rows get copied before a commit SET ARRAYSIZE determines how many rows are in a set.

EXAMPLE This example copies BOOKSHELF_CHECKOUT from the EDMESTON database to the

database the local SQL*Plus user is connected to The table LOCAL_CHECKOUT is created by the copy

The columns may be renamed at the destination Note the use of the dash (-) at the end of each line

This is required The command does not end with a semicolon (since it is a SQL*Plus command, not

a SQL command).See the SET command for options related to the COPY command.

copy from PRACTICE/PRACTICE@EDMESTON

create LOCAL_CHECKOUT (Borrower, Title)

using select Name, Title

CORR ( expr1 , expr2 ) [OVER ( analytic_clause )]

DESCRIPTION CORR returns the coefficient of correlation of a set of number pairs Bothexpr1

andexpr2 are number expressions Oracle applies the function to the set of (expr1, expr2) after eliminating

the pairs for which eitherexpr1 or expr2 is NULL Then Oracle makes the following computation:

COVAR_POP(expr1, expr2) / (STDDEV_POP(expr1) * STDDEV_POP(expr2))

The function returns a value of type NUMBER If the function is applied to an empty set, it

returns NULL.

Trang 10

FORMAT

CORR (expr1, expr2 ) OVER (analytic clause)

DESCRIPTION CORR returns the coefficient of correlation on a set of number pairs CORR can

be used as an aggregate or analytic function

CORR_K and CORR_S

FORMAT

{CORR_K | CORR_S }

(expr1, expr2 [, { COEFFICIENT |ONE_SIDED_SIG|TWO_SIDED_SIG}])

DESCRIPTION The CORR_K and CORR_S functions support nonparametric or rank correlations.

Correlation coefficients take a value ranging from 1 to –1 where 1 indicates a perfect relationship and

–1 a perfect inverse relationship The arguments must either be numeric or implicitly converted to a

numeric datatype ONE_SIDED_SIG is for one-tailed significance of the correlation, TWO_SIDED_SIG

is for two-tailed significance

CORRELATED QUERY

A correlated query is a subquery that is executed repeatedly, once for each value of a candidate row

selected by the main query The outcome of each execution of the subquery depends on the values of

one or more fields in the candidate row; that is, the subquery is correlated with the main query.See

DESCRIPTION COS returns the cosine of a value, an angle expressed in radians You can convert

a degree angle into radians by multiplying it by pi/180

COSH

SEE ALSO ACOS, ASIN, ATAN, ATAN2, COS, EXP, LN, LOG, SIN, SINH, TAN, TANH

FORMAT

COSH(value)

DESCRIPTION COSH returns the hyperbolic cosine of avalue

1072 Part IX: Alphabetical Reference

Trang 11

SEE ALSO AGGREGATE FUNCTIONS, Chapters 9 and 12

FORMAT

COUNT ( { * | [ DISTINCT | ALL ] expr } ) [OVER ( analytic_clause )]

DESCRIPTION COUNT counts the number of rows in which expression is non-NULL, which is

then returned by the query With DISTINCT, COUNT counts only the distinct non-NULL rows With *,

COUNT counts all rows, whether NULL or not.

COVAR_POP

FORMAT

COVAR_POP ( expr1 , expr2 ) [OVER ( analytic_clause )]

DESCRIPTION COVAR_POP returns the population covariance of a set of number pairs You can

use it as an aggregate or analytic function

Bothexpr1 and expr2 are number expressions Oracle applies the function to the set of (expr1, expr2)pairs after eliminating all pairs for which eitherexpr1 or expr2 is NULL Then Oracle makes the following

computation:

(SUM(expr1 * expr2) - SUM(expr2) * SUM(expr1) / n) / n

wherenis the number of (expr1, expr2) pairs where neither expr1 nor expr2 is NULL

COVAR_SAMP

FORMAT

COVAR_POP ( expr1 , expr2 ) [OVER ( analytic_clause )]

DESCRIPTION COVAR_SAMP returns the sample covariance of a set of number pairs You can

use it as an aggregate or analytic function

Bothexpr1 and expr2 are number expressions Oracle applies the function to the set of (expr1, expr2)pairs after eliminating all pairs for which eitherexpr1 or expr2 is NULL Then Oracle makes the following

computation:

(SUM(expr1 * expr2) - SUM(expr1) * SUM(expr2) / n) / (n-1)

wheren is the number of (expr1, expr2) pairs where neither expr1 nor expr2 is NULL.

CREATE CLUSTER

SEE ALSO CREATE INDEX, CREATE TABLE, Chapter 17

Trang 12

K M G T

)

physical_attributes_clause SIZE size_clause TABLESPACE tablespace INDEX

CACHE N0CACHE

;

Trang 13

DESCRIPTION CREATE CLUSTER creates a cluster for one or more tables Tables are added to the

cluster using CREATE TABLE with the CLUSTER clause CREATE CLUSTER requires at least one cluster

column from each of the tables These must have the same datatype and size, but are not required to

have the same name For the tables in a cluster, rows with the same cluster column values are kept

together on disk in the same area, the same logical block(s) This can improve performance when the

cluster columns are the columns by which the tables are usually joined

Each distinct value in each cluster column is stored only once, regardless of whether it occurs once

or many times in the tables and rows This typically can reduce the amount of disk space needed to

store the tables, but each table continues to appear as if it contains all of its own data Tables with LONG

columns cannot be clustered

cluster is the name created for the cluster column and datatype follow the method of CREATE TABLE, except that NULL and NOT NULL cannot be specified However, in the actual CREATE TABLE statement,

at least one cluster column in a cluster must be NOT NULL SIZE sets the size in bytes for a logical

block (not a physical block) SPACE is the cluster’s initial disk allocation, as used in CREATE TABLE.

SIZE should be the average amount of space needed to store all the rows from all the clustered

tables that are associated with a single cluster key A small SIZE value may increase the time needed

to access tables in the cluster, but can reduce disk space usage SIZE should be a proper divisor of the

physical block size If not, Oracle will use the next larger divisor If SIZE exceeds the physical block

size, Oracle will use the physical block size instead

By default, the cluster is indexed, and you must create an index on the cluster key before puttingany data in the cluster If you specify the hash cluster form, however, you don’t need to (and can’t)

create an index on the cluster key Instead, Oracle uses a hash function to store the rows of the table

You can create your own hash value as a column of the table and use that for hashing with the HASH

IS clause to tell Oracle to use that column as the hash value Otherwise, Oracle uses an internal hash

function based on the columns of the cluster key The HASHKEYS clause actually creates the hash cluster

and specifies the number of hash values, rounded to the nearest prime number The minimum value is 2

See STORAGE for details on the common storage clause parameters.

CREATE CONTEXT

FORMAT

CREATE [OR REPLACE] CONTEXT namespace USING [schema ] package

[ INITIALIZED { EXTERNALLY | GLOBALLY }

| ACCESSED GLOBALLY ] ;

DESCRIPTION A context is a set of attributes used to secure an application CREATE CONTEXT

creates a namespace for a context and associates the namespace with the externally created package

that sets the context To create a context namespace, you must have the CREATE ANY CONTEXT system

privilege

CREATE CONTROLFILE

SEE ALSO ALTER DATABASE, CREATE DATABASE

Trang 14

create_controlfile::=

logfile_clause::=

character_set_clause::=

DESCRIPTION You can use the CREATE CONTROLFILE command to re-create a control file if

you have lost your current control file to media failure, if you want to change the name of your database,

or if you want to change one of the options for the redo log file or a datafile In general, this command

should be used only by experienced database administrators

CHARACTER SET character_set

;

Trang 15

The REUSE option lets existing control files be reused If you specify the name of an existing control file but do not use the REUSE option, the command will return an error The SET option changes the

name of the database, specified by the DATABASE clause The LOGFILE clause specifies the redo log

file groups, all of which must exist The RESETLOGS versus NORESETLOGS clause tells Oracle to reset

the current logs or not The DATAFILE line specifies the datafiles for the database, all of which must exist.

The MAXLOGFILES option specifies the maximum number of redo log file groups that can be created The MAXLOGMEMBERS option specifies the number of copies for a redo log group The

MAXLOGHISTORY option specifies the number of archived redo log file groups for Real Application

Clusters The MAXDATAFILES option specifies the maximum number of datafiles that can ever be

created for the database The MAXINSTANCES option gives the maximum number of Oracle instances

that can mount and open the database The ARCHIVELOG and NOARCHIVELOG options turn archiving

of the redo log files on and off, respectively

The CREATE CONTROLFILE command needed for an existing database can be generated via the

ALTER DATABASE BACKUP CONTROLFILE TO TRACE command.

As of Oracle Database 10g, you can specify Automatic Storage Management files as well as filesystem files

CREATE DATABASE

SEE ALSO ALTER DATABASE, CREATE CONTROLFILE, CREATE ROLLBACK SEGMENT, CREATE

TABLESPACE, SHUTDOWN, STARTUP, Chapters 2 and 46

MAXDATAFILES integer MAXINSTANCES integer CHARACTER SET charset NATIONAL CHARACTER SET charset

SET DEFAULT

BIGFILE SMALLFILE

TABLESPACE

database_logging_clauses tablespace_clauses set_time_zone_clause

;

Trang 16

tablespace_clauses::=

default_tablespace::=

default_temp_tablespace::=

1078 Part IX: Alphabetical Reference

DEFAULT TABLESPACE tablespace

DATAFILE datafile_tempfile_spec

extent_management_clause

BIGFILE SMALLFILE

DEFAULT TEMPORARY TABLESPACE tablespace

MAXLOGFILES integer MAXLOGMEMBERS integer MAXLOGHISTORY integer ARCHIVELOG

NOARCHIVELOG FORCE LOGGING

Trang 17

size_clause::=

undo_tablespace::=

set_time_zone_clause::=

DESCRIPTION database is the database name, and must have eight characters or fewer DB_NAME

in init.ora contains the default database name In general, this command should be used only by

experienced database administrators

NOTE

Using this command in an existing database will erase the specifieddatafiles

file_definition defines the redo log file and datafile names and sizes

'file' [SIZE integer [K | M] [REUSE]

SIZE is the number of bytes set aside for this file Suffixing this with K multiplies the value by 1024;

M multiplies it by 1048576 (G and T are also supported) REUSE (without SIZE) means destroy the contents

integer

K M G T

BIGFILE SMALL

UNDO TABLESPACE tablespace

DATAFILE file_specification

,

+ –

Trang 18

of any file by this name and associate the name with this database REUSE with SIZE creates the file

if it doesn’t exist, and checks its size if it does exist CONTROLFILE REUSE overwrites the existing

control files defined by the CONTROL_FILES parameter in the initialization parameter file

LOGFILE names the files to be used as redo log files If this parameter is not used, Oracle creates two

by default MAXLOGFILES overrides the LOG_FILES initialization parameter, and defines the maximum

number of redo log files that can ever be created for this database This number cannot be increased later

except by re-creating the control file The minimum number for files is two A high number only makes a

somewhat larger control file

DATAFILE names the files to be used for the database itself MAXDATAFILES sets the absolute upper

limit for files that can be created for this database, and overrides the DB_FILES initialization parameter

A high number only makes a somewhat larger control file

As of Oracle Database 10g, you can specify Automatic Storage Management files as well as file

system files When the AUTOEXTEND option is turned ON for a datafile, the datafile will dynamically

extend as needed in increments of NEXT size, to a maximum of MAXSIZE (or UNLIMITED).

MAXINSTANCES overrides the INSTANCES parameter in init.ora and sets the maximum number

of simultaneous instances that can mount and open this database

ARCHIVELOG and NOARCHIVELOG define the way redo log files are used when the database

is first created NOARCHIVELOG is the default, and means that redo log files will get reused without

saving their contents elsewhere This provides instance recovery but will not recover from a media

failure, such as a disk crash ARCHIVELOG forces redo log files to be archived (usually to another disk

or a tape), so that you can recover from a media failure This mode also supports instance recovery

This parameter can be reset by ALTER DATABASE.

The MAXLOGMEMBERS option specifies the maximum number of copies of a redo log file group.

The MAXLOGHISTORY option specifies the maximum number of archived redo log files, useful only

for the Real Application Clusters when you are archiving redo log files The CHARACTER SET option

specifies the character set used to store data, which depends on the operating system

For more automated handling of undo (rollback) segments, you can specify the UNDO TABLESPACE

clause to allocate a tablespace specifically to hold undo data The database must be started in Automatic

Undo Management (AUM) mode

You can use the DEFAULT TEMPORARY TABLESPACE clause to designate a non-SYSTEM tablespace

as the default temporary tablespace for all new users created in the database

As of Oracle Database 10g, you can use the CREATE DATABASE command to do the following:

■ Create a default permanent tablespace for the database

■ Specify datafiles for the SYSAUX tablespace

■ Specify a bigfile tablespace as the default for the database

■ Override the default for the undo and default temporary tablespaces

CREATE DATABASE LINK

SEE ALSO CREATE SYNONYM, SELECT, Chapter 23

FORMAT

CREATE [SHARED] [PUBLIC] DATABASE LINK dblink

[ CONNECT TO { CURRENT_USER | user IDENTIFIED BY password

[AUTHENTICATED BY user IDENTIFIED BY password] }

| AUTHENTICATED BY user IDENTIFIED BY password]

[USING 'connect_string'];

1080 Part IX: Alphabetical Reference

Trang 19

DESCRIPTION dblink is the name given to the link connect_string is the definition of the remote

database that can be accessed through Oracle Net and defines the link between a local database and a

username on a remote database PUBLIC links can be created only by a user with the CREATE PUBLIC

DATABASE LINK system privilege, but are then available to all users except those who have created a

private link with the same name If PUBLIC isn’t specified, the link is only available to the user who

executed the CREATE DATABASE LINK statement.connect_string is the Oracle Net service name for

the remote database

Remote tables can be accessed just like local tables, except that the table name must be suffixed

by @link in the FROM clause of the SELECT statement Most systems set the maximum number of

simultaneous links to four The DBA can increase this number with the OPEN_LINKS parameter in init.ora

Tree-structured queries are limited They may not use the PRIOR operator except in the CONNECT

BY clause START WITH cannot contain a subquery CONNECT BY and START WITH cannot use the

function USERENV('ENTRYID'), or the pseudo-column RowNum.

To create a database link, you must have CREATE DATABASE LINK privilege in the local database,and the CREATE SESSION privilege in a remote database To create a public database link, you must

have the CREATE PUBLIC DATABASE LINK system privilege

If you use the CONNECT TO CURRENT_USER clause, the link will attempt to open a connection

in the remote database by using your current username and password You therefore need to coordinate

any password changes you make between the local database and the remote database, or else database

links may stop working

If you use the shared server architecture, you can create SHARED database links that eliminate the need for many separate dedicated connections via links When you create a SHARED link, you

must supply a valid username and password in the remote database to use as an authentication for

the connection

EXAMPLES The following defines a link named EDMESTON_BOOKS that connects to the Practice

username in the EDMESTON database:

create database link EDMESTON_BOOKS

connect to Practice identified by Practice

using 'EDMESTON';

You now can query Practice’s tables like this:

select Title, Publisher

from BOOKSHELF@EDMESTON_BOOKS;

A synonym could also be created to hide the remoteness of the tables:

create synonym BOOKSHELF for BOOKSHELF@EDMESTON_BOOKS;

;

Trang 20

DESCRIPTION CREATE DIMENSION creates hierarchies among related columns in tables, for

use by the optimizer The optimizer uses dimension values when determining whether a materialized

view will return the same data as its base table To create a dimension, you must have CREATE

DIMENSION privilege; to create a dimension in another user’s schema, you must have the CREATE

ANY DIMENSION privilege

LEVEL defines the level within the dimension HIERARCHY defines the relationships among the

levels ATTRIBUTE assigns specific attributes to levels within the dimension JOIN_KEY defines the

join clauses between the levels

As of Oracle Database 10g, you can assign a name to a dimension attribute that is different fromthe level name

EXAMPLES Consider a geography dimension Continents are divided into countries, so there is

a hierarchy between country data and continent data For a table named COUNTRY, with columns

Country and Continent, and a second table named CONTINENT, with a column named Continent:

1082 Part IX: Alphabetical Reference

HIERARCHY hierarchy ( child_level CHILD OF parent_level

ATTRIBUTE level DETERMINES

Trang 21

create table CONTINENT (

Continent VARCHAR2(30));

create table COUNTRY (

Country VARCHAR2(30) not null,

Continent VARCHAR2(30));

create dimension GEOGRAPHY

level COUNTRY_ID is COUNTRY.Countrylevel CONTINENT_ID is CONTINENT.Continenthierarchy COUNTRY_ROLLUP (

COUNTRY_ID child ofCONTINENT_ID

join key COUNTRY.Continent references CONTINENT_ID);

CREATE DIRECTORY

SEE ALSO BFILE, Chapters 22, 26, and 35

FORMAT

CREATE [OR REPLACE] DIRECTORY directory AS 'path_name';

DESCRIPTION Within Oracle, a “directory” is an alias for an operating system directory You

must create a directory prior to accessing BFILE datatype values or external tables.See Chapter 26 for

details on the creation and management of external tables

Trang 22

DESCRIPTION

NOTE CREATE DISKGROUP is valid only if you are using Automatic Storage

Management (ASM) and you have started an ASM instance

CREATE DISKGROUP creates a collection of disks Oracle manages a disk group as a logical unit

and evenly spreads each file across the disks to balance I/O Oracle automatically distributes database

files across the available disks in disk groups and rebalances the storage when the storage configuration

changes CREATE DISKGROUP creates a disk group, assigns disks to the disk group, and mounts the

disk group for the first time

CREATE FUNCTION

SEE ALSO ALTER FUNCTION, BLOCK STRUCTURE, CREATE LIBRARY, CREATE PACKAGE,

CREATE PROCEDURE, DATATYPES, DROP FUNCTION, Chapter 31

datatype ,

) RETURN datatype

invoker_rights_clause DETERMINISTIC parallel_enable_clause

AGGREGATE PIPELINED

;

Trang 24

specified by the RETURN clause The PL/SQL block defines the behavior of the function as a series of

declarations, PL/SQL program statements, and exceptions

The IN qualifier means that you have to specify a value for the parameter when you call the function,

but since you always have to do this for a function, the syntax is optional In a procedure, you can

have other kinds of parameters The difference between a function and a procedure is that a function

returns a value to the calling environment

In order to create a function, you must have the CREATE PROCEDURE system privilege To create

a function in another user’s account, you must have the CREATE ANY PROCEDURE system privilege

Your function can use C libraries that are stored outside of the database (see CREATE LIBRARY).

If you use Java within your function, you can provide a Java declaration within the LANGUAGE clause.

The INVOKER_RIGHTS clause lets you specify whether the function executes with the privileges of

the function owner (the definer) or the current user (the invoker)

INDEX

schema

index ON

cluster_index_clause table_index_clause bitmap_join_index_clause

) index_properties

Trang 25

global_partitioned_index local_partitioned_index index_attributes domain_index_clause

schema

table (

schema

table t_alias

column

ASC DESC ,

WHERE condition

local_partitioned_index

index_attributes

physical_attributes_clause logging_clause ONLINE COMPUTE STATISTICS

TABLESPACE

tablespace DEFAULT key_compression

SORT NOSORT REVERSE parallel_clause

Trang 26

LOGGING NOLOGGING

partition partitioning_storage_clause ,

)

Trang 27

, ) segment_attributes_clause

LOCAL

on_range_partitioned_table on_list_partitioned_table on_hash_partitioned_table on_comp_partitioned_table

( PARTITION

partition

segment_attributes_clause key_compression ,

Trang 28

physical_attributes_clause TABLESPACE tablespace logging_clause

,

)

Trang 29

parallel_clause::=

DESCRIPTION index is a name you assign to this index It’s usually a good idea to make it reflect

the table and columns being indexed.table and column(s) are the table and column(s) for which the index

is to be created A unique index guarantees that each indexed row is unique on the values of the index

columns You can use the UNIQUE constraint on the columns to automatically create unique indexes

Specifying multiple columns will create a composite index ASC and DESC mean ascending and descending.

CLUSTER is the name of the cluster key that is indexed for a cluster Clusters must have their keys indexed

for their associated tables to be accessed PCTFREE is the percentage of space to leave free in the

index for new entries and updates The minimum is zero

TABLESPACE is the name of the tablespace to which this index is assigned The physical attributes

section contains subclauses that are described under STORAGE NOSORT is an option whose primary value

is in reducing the time to create an index if, and only if, the values in the column being indexed are already

in ascending order It doesn’t harm anything if they later fall out of ascending order, but NOSORT works

only if they are in order when the index is created If the rows are not in order, CREATE INDEX will return

an error message, will not damage anything, and will allow you to rerun it without the NOSORT option.

PARALLEL, along with DEGREE and INSTANCES, specifies the parallel characteristics of the index.

DEGREE specifies the number of query servers to use to create the index; INSTANCES specifies how

the index is to be split among instances of Real Application Clusters for parallel query processing

An integern specifies that the index is to be split among the specified number of available instances

In order to create an index, you must own the indexed table, have INDEX privilege on the table,

or have the CREATE ANY INDEX system privilege To create a function-based index, you must have

the QUERY REWRITE privilege

BITMAP creates a bitmap index, which can be useful for columns with few distinct values The PARTITION clauses create indexes on partitioned tables Bitmap join indexes store index key values

for multiple tables in a single index (usually for data warehouse applications) Bitmap join indexes use

the FROM and WHERE clauses to specify the tables involved and the join conditions.

REVERSE stores the bytes of the indexed value in reverse order You cannot reverse a bitmap index.

)

Trang 30

COMPRESS saves storage space by compressing nonunique, nonpartitioned indexes During data

retrieval, the data will be displayed as if it were uncompressed You can turn off index compression;

re-create the index using the clause NOCOMPRESS.

COMPUTE STATISTICS analyzes the index data as the index is created.

As of Oracle Database 10g, you can create global hash-partitioned indexes

DESCRIPTION CREATE INDEXTYPE specifies the routines used by a domain index To create an

indextype, you must have the CREATE INDEXTYPE system privilege To create an indextype in another

user’s schema, you must have the CREATE ANY INDEXTYPE system privilege

As of Oracle Database 10g, CREATE INDEXTYPE supports array inserts using the ODCIIndexInsertmethod

CREATE JAVA

SEE ALSO ALTER JAVA, DROP JAVA, Chapters 37, 38, and 39

1092 Part IX: Alphabetical Reference

( schema

type

, schema

varray_type

) ,

using_type_clause

Trang 31

create_java::=

invoker_rights_clause::=

DESCRIPTION CREATE JAVA creates a Java source, class, or resource You must have the

CREATE PROCEDURE system privilege or (to create the object in another user’s schema) the CREATE

ANY PROCEDURE system privilege To replace such a schema object in another user’s schema, you

must have the ALTER ANY PROCEDURE system privilege

The JAVA SOURCE, JAVA CLASS, and JAVA RESOURCE clauses load sources, classes, and resources,

respectively

The AUTHID lets you specify whether the function executes with the privileges of the function

owner or the current user

EXAMPLE The following command creates a Java source:

create java source named "Hello" as

public class Hello (public static String hello() (return "Hello World"; ) );

AUTHID

CURRENT_USER DEFINER

CREATE

OR REPLACE

AND RESOLVE

JAVA

SOURCE RESOURCE

subquery

’ key_for_BLOB ’

AS source_text

;

Trang 32

CREATE LIBRARY

SEE ALSO CREATE FUNCTION, CREATE PACKAGE BODY, CREATE PROCEDURE, Chapter 31

FORMAT

CREATE [OR REPLACE] LIBRARY [schema ] libname

{ IS | AS } 'filespec' [AGENT 'agent_dblink'];

DESCRIPTION CREATE LIBRARY creates a library object, allowing you to reference an

operating-system shared library, from which SQL and PL/SQL can call external 3GL functions and procedures

To use the procedures and functions stored in the library, you must have been granted EXECUTE privilege

on the library Specify the AGENT clause if you want external procedures to be run from a database

link other than the server Oracle will use the database link specified byagent_dblink to run external

procedures If you omit this clause, the default agent on the server (extproc) will run external procedures

CREATE MATERIALIZED VIEW

SEE ALSO ALTER MATERIALIZED VIEW, CREATE MATERIALIZED VIEW LOG, DROP

MATERIALIZED VIEW, STORAGE, Chapter 24

FORMAT

create_materialized_view::=

1094 Part IX: Alphabetical Reference

CREATE MATERIALIZED VIEW

REDUCED PRECISION

physical_properties materialized_view_props

USING INDEX

physical_attributes_clause TABLESPACE tablespace

FOR UPDATE

DISABLE ENABLE

QUERY REWRITE

AS subquery ;

Trang 33

SCOPE FOR (

ref_column ref_attribute

) IS

schema scope_table_name

c_alias ,

mapping_table_clause PCTTHRESHOLD integer key_compression index_org_overflow_clause

, )

INCLUDING column_name

OVERFLOW

segment_attributes_clause

Trang 34

ON DEMAND COMMIT START WITH NEXT

date

WITH

PRIMARY KEY ROWID

USING

DEFAULT

MASTER LOCAL

ROLLBACK SEGMENT MASTER

LOCAL

ROLLBACK SEGMENT rollback_segment

USING

ENFORCED TRUSTED

CONSTRAINTS

NEVER REFRESH

physical_attributes_clause TABLESPACE tablespace logging_clause

PCTFREE integer PCTUSED integer INITRANS integer storage_clause

Trang 35

COMPRESS NOCOMPRESS

object_type_col_properties nested_table_col_properties

varray_col_properties LOB_storage_clause

SUBSTITUTABLE AT ALL LEVELS

NESTED TABLE

nested_item COLUMN_VALUE

substitutable_column_clause

STORE AS storage_table

( ( object_properties ) physical_properties column_properties

)

LOCATOR VALUE

Trang 36

LOB ( LOB_item

,

) STORE AS ( LOB_parameters )

( LOB_item ) STORE AS

LOB_segname ( LOB_parameters ) LOB_segname

( LOB_parameters )

TABLESPACE tablespace ENABLE

DISABLE

storage_clause CHUNK integer PCTVERSION integer RETENTION

FREEPOOLS integer CACHE

( SUBPARTITION subpartition

LOB_storage_clause varray_col_properties

)

Trang 37

build_clause::=

DESCRIPTION The keyword SNAPSHOT is supported in place of MATERIALIZED VIEW for

backward compatibility

CREATE MATERIALIZED VIEW creates a materialized view, a table that holds the results of a query,

usually on one or more tables, called master tables The master tables may be in a local database or in a

remote database You can have the data refreshed at intervals by using the REFRESH clause.

To enable a materialized view for query rewrite, you must have the QUERY REWRITE system privilege

If the materialized view is based on objects in other schemas, you must have the GLOBAL QUERY

REWRITE privilege

Materialized views cannot contain LONG columns or reference any objects owned by SYS

A FAST refresh uses the materialized view log associated with the master table(s) to refresh the materialized view A COMPLETE refresh reexecutes the query A FORCE refresh lets Oracle make

the choice between a FAST or a COMPLETE refresh Oracle first refreshes the materialized view on

the START WITH date If you give a NEXT date, Oracle refreshes the materialized view at intervals

specified by the difference between the START WITH and NEXT dates.

A simple materialized view selects data from a single master table using a simple query A complex

materialized view selects data using a GROUP BY, CONNECT BY, subquery, join, or set operation in the

query Oracle can do a FAST refresh only on simple materialized views that have materialized view logs.

To create a materialized view in your schema, you must have the CREATE MATERIALIZED VIEWsystem privilege To create a materialized view in another user’s schema, you must have the CREATE

ANY MATERIALIZED VIEW system privilege

As of Oracle Database 10g, the refresh operations are enhanced See Chapter 24 for details onrefresh options

EXAMPLE

create materialized view LOCAL_BOOKSHELF

storage (initial 100K next 100K pctincrease 0)

tablespace USERS

refresh force

start with SysDate next SysDate+7

with primary key

as

select * from BOOKSHELF@REMOTE_CONNECT;

CREATE MATERIALIZED VIEW LOG

SEE ALSO ALTER MATERIALIZED VIEW LOG, CREATE MATERIALIZED VIEW, DROP

MATERIALIZED VIEW LOG, STORAGE, Chapter 24

Trang 38

1100 Part IX: Alphabetical Reference

CREATE MATERIALIZED VIEW LOG ON

schema

table

physical_attributes_clause TABLESPACE tablespace logging_clause

CACHE

WITH

OBJECT ID PRIMARY KEY ROWID SEQUENCE

( column , )

,

new_values_clause

;

PCTFREE integer PCTUSED integer INITRANS integer storage_clause

LOGGING NOLOGGING

NOPARALLEL

PARALLEL

integer

Trang 39

DESCRIPTION The keyword SNAPSHOT is supported in place of MATERIALIZED VIEW for

backward compatibility

CREATE MATERIALIZED VIEW LOG creates a table associated with the master table of a materialized

view that tracks changes to the master table’s data Oracle uses the materialized view log to FAST refresh

the materialized views of a master table The storage options specify the storage of the table Oracle

logs database changes only if there is a simple materialized view based on the master table

You can have only one log for a given master table, and the log is stored in the same schema as themaster table To create a materialized view log on your own master table, you must have the CREATE

TABLE system privilege If the master table is in another user’s schema, you must have the CREATE

ANY TABLE and COMMENT ANY TABLE system privileges as well as the SELECT privilege on the

ANCILLARY TO primary_operator ( parameter_type

,

) ,

context_clause

Trang 40

using_function_clause::=

DESCRIPTION CREATE OPERATOR creates a new operator and defines its bindings You can

reference operators in indextypes and in SQL statements The operators, in turn, reference functions,

packages, types, and other user-defined objects

To create an operator, you must have EXECUTE privilege on the functions and operators referenced

by the operator, and the CREATE OPERATOR system privilege If the operator is created in another user’s

schema, you must have the CREATE ANY OPERATOR system privilege

As of Oracle Database 10g, you can pass column information to the functional implementation ofthe operator

CREATE OUTLINE

SEE ALSO Chapter 43

FORMAT

CREATE [OR REPLACE] [ PUBLIC | PRIVATE ] OUTLINE [outline]

[FROM [ PUBLIC | PRIVATE ] source_outline]

[FOR CATEGORY category]

[ON statement];

DESCRIPTION CREATE OUTLINE creates a stored outline, which is a set of hints used to create

the execution plan of the associated query Later executions of the query will use the same set of hints

You can group stored outlines into categories

To create an operator, you must have the CREATE ANY OUTLINE system privilege

EXAMPLE

create outline TEST

for category DEVELOPMENT

on select AuthorName, COUNT(AuthorName) from BOOKSHELF_AUTHOR group by AuthorName;

CREATE PACKAGE

SEE ALSO ALTER PACKAGE, CREATE FUNCTION, CREATE PACKAGE BODY, CREATE

PROCEDURE, CURSOR, DROP PACKAGE, EXCEPTION, RECORD, TABLE, VARIABLE

function_name

WITH INDEX CONTEXT , SCAN CONTEXT implementation_type

COMPUTE ANCILLARY DATA

WITH COLUMN CONTEXT

Ngày đăng: 08/08/2014, 20:21

TỪ KHÓA LIÊN QUAN