
- •Contents
- •Send Us Your Comments
- •Preface
- •What’s New in SQL Reference?
- •1 Introduction to Oracle SQL
- •History of SQL
- •SQL Standards
- •Embedded SQL
- •Lexical Conventions
- •Tools Support
- •2 Basic Elements of Oracle SQL
- •Datatypes
- •Oracle Built-in Datatypes
- •ANSI, DB2, and SQL/DS Datatypes
- •Oracle-Supplied Types
- •"Any" Types
- •XML Types
- •Spatial Type
- •Media Types
- •Datatype Comparison Rules
- •Data Conversion
- •Literals
- •Text Literals
- •Integer Literals
- •Number Literals
- •Interval Literals
- •Format Models
- •Number Format Models
- •Date Format Models
- •String-to-Date Conversion Rules
- •XML Format Model
- •Nulls
- •Nulls in SQL Functions
- •Nulls with Comparison Conditions
- •Nulls in Conditions
- •Pseudocolumns
- •CURRVAL and NEXTVAL
- •LEVEL
- •ROWID
- •ROWNUM
- •XMLDATA
- •Comments
- •Comments Within SQL Statements
- •Comments on Schema Objects
- •Hints
- •Database Objects
- •Schema Objects
- •Nonschema Objects
- •Parts of Schema Objects
- •Schema Object Names and Qualifiers
- •Schema Object Naming Rules
- •Schema Object Naming Examples
- •Schema Object Naming Guidelines
- •Syntax for Schema Objects and Parts in SQL Statements
- •How Oracle Resolves Schema Object References
- •Referring to Objects in Other Schemas
- •Referring to Objects in Remote Databases
- •Referencing Object Type Attributes and Methods
- •3 Operators
- •About SQL Operators
- •Unary and Binary Operators
- •Operator Precedence
- •Arithmetic Operators
- •Concatenation Operator
- •Set Operators
- •4 Expressions
- •About SQL Expressions
- •Simple Expressions
- •Compound Expressions
- •CASE Expressions
- •CURSOR Expressions
- •Datetime Expressions
- •Function Expressions
- •INTERVAL Expressions
- •Object Access Expressions
- •Scalar Subquery Expressions
- •Type Constructor Expressions
- •Variable Expressions
- •Expression Lists
- •5 Conditions
- •About SQL Conditions
- •Condition Precedence
- •Comparison Conditions
- •Simple Comparison Conditions
- •Group Comparison Conditions
- •Logical Conditions
- •Membership Conditions
- •Range Conditions
- •Null Conditions
- •EQUALS_PATH
- •EXISTS Conditions
- •LIKE Conditions
- •IS OF type Conditions
- •UNDER_PATH
- •Compound Conditions
- •6 Functions
- •SQL Functions
- •Single-Row Functions
- •Aggregate Functions
- •Analytic Functions
- •Object Reference Functions
- •Alphabetical Listing of SQL Functions
- •ACOS
- •ADD_MONTHS
- •ASCII
- •ASCIISTR
- •ASIN
- •ATAN
- •ATAN2
- •BFILENAME
- •BITAND
- •CAST
- •CEIL
- •CHARTOROWID
- •COALESCE
- •COMPOSE
- •CONCAT
- •CONVERT
- •CORR
- •COSH
- •COUNT
- •COVAR_POP
- •COVAR_SAMP
- •CUME_DIST
- •CURRENT_DATE
- •CURRENT_TIMESTAMP
- •DBTIMEZONE
- •DECODE
- •DECOMPOSE
- •DENSE_RANK
- •DEPTH
- •DEREF
- •DUMP
- •EMPTY_BLOB, EMPTY_CLOB
- •EXISTSNODE
- •EXTRACT (datetime)
- •EXTRACT (XML)
- •EXTRACTVALUE
- •FIRST
- •FIRST_VALUE
- •FLOOR
- •FROM_TZ
- •GREATEST
- •GROUP_ID
- •GROUPING
- •GROUPING_ID
- •HEXTORAW
- •INITCAP
- •INSTR
- •LAST
- •LAST_DAY
- •LAST_VALUE
- •LEAD
- •LEAST
- •LENGTH
- •LOCALTIMESTAMP
- •LOWER
- •LPAD
- •LTRIM
- •MAKE_REF
- •MONTHS_BETWEEN
- •NCHR
- •NEW_TIME
- •NEXT_DAY
- •NLS_CHARSET_DECL_LEN
- •NLS_CHARSET_ID
- •NLS_CHARSET_NAME
- •NLS_INITCAP
- •NLS_LOWER
- •NLSSORT
- •NLS_UPPER
- •NTILE
- •NULLIF
- •NUMTODSINTERVAL
- •NUMTOYMINTERVAL
- •PATH
- •PERCENT_RANK
- •PERCENTILE_CONT
- •PERCENTILE_DISC
- •POWER
- •RANK
- •RATIO_TO_REPORT
- •RAWTOHEX
- •RAWTONHEX
- •REFTOHEX
- •REGR_ (Linear Regression) Functions
- •REPLACE
- •ROUND (number)
- •ROUND (date)
- •ROW_NUMBER
- •ROWIDTOCHAR
- •ROWIDTONCHAR
- •RPAD
- •RTRIM
- •SESSIONTIMEZONE
- •SIGN
- •SINH
- •SOUNDEX
- •SQRT
- •STDDEV
- •STDDEV_POP
- •STDDEV_SAMP
- •SUBSTR
- •SYS_CONNECT_BY_PATH
- •SYS_CONTEXT
- •SYS_DBURIGEN
- •SYS_EXTRACT_UTC
- •SYS_GUID
- •SYS_TYPEID
- •SYS_XMLAGG
- •SYS_XMLGEN
- •SYSDATE
- •SYSTIMESTAMP
- •TANH
- •TO_CHAR (character)
- •TO_CHAR (datetime)
- •TO_CHAR (number)
- •TO_CLOB
- •TO_DATE
- •TO_DSINTERVAL
- •TO_MULTI_BYTE
- •TO_NCHAR (character)
- •TO_NCHAR (datetime)
- •TO_NCHAR (number)
- •TO_NCLOB
- •TO_NUMBER
- •TO_SINGLE_BYTE
- •TO_TIMESTAMP
- •TO_TIMESTAMP_TZ
- •TO_YMINTERVAL
- •TRANSLATE
- •TRANSLATE ... USING
- •TREAT
- •TRIM
- •TRUNC (number)
- •TRUNC (date)
- •TZ_OFFSET
- •UNISTR
- •UPDATEXML
- •UPPER
- •USER
- •USERENV
- •VALUE
- •VAR_SAMP
- •VARIANCE
- •VSIZE
- •WIDTH_BUCKET
- •XMLAGG
- •XMLCOLATTVAL
- •XMLCONCAT
- •XMLELEMENT
- •XMLFOREST
- •XMLSEQUENCE
- •XMLTRANSFORM
- •ROUND and TRUNC Date Functions
- •User-Defined Functions
- •Prerequisites
- •Name Precedence
- •7 Common SQL DDL Clauses
- •allocate_extent_clause
- •constraints
- •deallocate_unused_clause
- •file_specification
- •logging_clause
- •parallel_clause
- •physical_attributes_clause
- •storage_clause
- •8 SQL Queries and Subqueries
- •About Queries and Subqueries
- •Creating Simple Queries
- •Hierarchical Queries
- •The UNION [ALL], INTERSECT, MINUS Operators
- •Sorting Query Results
- •Joins
- •Using Subqueries
- •Unnesting of Nested Subqueries
- •Selecting from the DUAL Table
- •Distributed Queries
- •9 SQL Statements: ALTER CLUSTER to ALTER SEQUENCE
- •Types of SQL Statements
- •Organization of SQL Statements
- •ALTER CLUSTER
- •ALTER DATABASE
- •ALTER DIMENSION
- •ALTER FUNCTION
- •ALTER INDEX
- •ALTER INDEXTYPE
- •ALTER JAVA
- •ALTER MATERIALIZED VIEW
- •ALTER MATERIALIZED VIEW LOG
- •ALTER OPERATOR
- •ALTER OUTLINE
- •ALTER PACKAGE
- •ALTER PROCEDURE
- •ALTER PROFILE
- •ALTER RESOURCE COST
- •ALTER ROLE
- •ALTER ROLLBACK SEGMENT
- •ALTER SEQUENCE
- •10 SQL Statements: ALTER SESSION to ALTER SYSTEM
- •ALTER SESSION
- •ALTER SYSTEM
- •ALTER TABLE
- •ALTER TABLESPACE
- •ALTER TRIGGER
- •ALTER TYPE
- •ALTER USER
- •ALTER VIEW
- •ANALYZE
- •ASSOCIATE STATISTICS
- •AUDIT
- •CALL
- •COMMENT
- •COMMIT
- •13 SQL Statements: CREATE CLUSTER to CREATE JAVA
- •CREATE CLUSTER
- •CREATE CONTEXT
- •CREATE CONTROLFILE
- •CREATE DATABASE
- •CREATE DATABASE LINK
- •CREATE DIMENSION
- •CREATE DIRECTORY
- •CREATE FUNCTION
- •CREATE INDEX
- •CREATE INDEXTYPE
- •CREATE JAVA
- •14 SQL Statements: CREATE LIBRARY to CREATE SPFILE
- •CREATE LIBRARY
- •CREATE MATERIALIZED VIEW
- •CREATE MATERIALIZED VIEW LOG
- •CREATE OPERATOR
- •CREATE OUTLINE
- •CREATE PACKAGE
- •CREATE PACKAGE BODY
- •CREATE PFILE
- •CREATE PROCEDURE
- •CREATE PROFILE
- •CREATE ROLE
- •CREATE ROLLBACK SEGMENT
- •CREATE SCHEMA
- •CREATE SEQUENCE
- •CREATE SPFILE
- •15 SQL Statements: CREATE SYNONYM to CREATE TRIGGER
- •CREATE SYNONYM
- •CREATE TABLE
- •CREATE TABLESPACE
- •CREATE TEMPORARY TABLESPACE
- •CREATE TRIGGER
- •CREATE TYPE
- •CREATE TYPE BODY
- •CREATE USER
- •CREATE VIEW
- •DELETE
- •DISASSOCIATE STATISTICS
- •DROP CLUSTER
- •DROP CONTEXT
- •DROP DATABASE LINK
- •DROP DIMENSION
- •DROP DIRECTORY
- •DROP FUNCTION
- •DROP INDEX
- •DROP INDEXTYPE
- •DROP JAVA
- •DROP LIBRARY
- •DROP MATERIALIZED VIEW
- •DROP MATERIALIZED VIEW LOG
- •DROP OPERATOR
- •DROP OUTLINE
- •DROP PACKAGE
- •DROP PROCEDURE
- •DROP PROFILE
- •DROP ROLE
- •DROP ROLLBACK SEGMENT
- •17 SQL Statements: DROP SEQUENCE to ROLLBACK
- •DROP SEQUENCE
- •DROP SYNONYM
- •DROP TABLE
- •DROP TABLESPACE
- •DROP TRIGGER
- •DROP TYPE
- •DROP TYPE BODY
- •DROP USER
- •DROP VIEW
- •EXPLAIN PLAN
- •GRANT
- •INSERT
- •LOCK TABLE
- •MERGE
- •NOAUDIT
- •RENAME
- •REVOKE
- •ROLLBACK
- •18 SQL Statements: SAVEPOINT to UPDATE
- •SAVEPOINT
- •SELECT
- •SET CONSTRAINT[S]
- •SET ROLE
- •SET TRANSACTION
- •TRUNCATE
- •UPDATE
- •Required Keywords and Parameters
- •Optional Keywords and Parameters
- •Syntax Loops
- •Multipart Diagrams
- •Database Objects
- •ANSI Standards
- •ISO Standards
- •Oracle Compliance
- •FIPS Compliance
- •Oracle Extensions to Standard SQL
- •Character Set Support
- •Using Extensible Indexing
- •Using XML in SQL Statements
- •Index

AUDIT
AUDIT
Purpose
Use the AUDIT statement to:
■Track the occurrence of SQL statements in subsequent user sessions. You can track the occurrence of a specific SQL statement or of all SQL statements authorized by a particular system privilege. Auditing operations on SQL statements apply only to subsequent sessions, not to current sessions.
■Track operations on a specific schema object. Auditing operations on schema objects apply to current sessions as well as to subsequent sessions.
See Also:
■Oracle9i Supplied PL/SQL Packages and Types Reference for information on the DBMS_FGA package, which lets you create and administer value-based auditing policies
■NOAUDIT on page 17-81 for information on disabling auditing of SQL statement
Prerequisites
To audit occurrences of a SQL statement, you must have AUDIT SYSTEM system privilege.
To audit operations on a schema object, the object you choose for auditing must be in your own schema or you must have AUDIT ANY system privilege. In addition, if the object you choose for auditing is a directory object, even if you created it, then you must have AUDIT ANY system privilege.
To collect auditing results, you must set the initialization parameter AUDIT_TRAIL to DB. You can specify auditing options regardless of whether auditing is enabled. However, Oracle does not generate audit records until you enable auditing.
See Also: Oracle9i Database Reference for information on the
AUDIT_TRAIL parameter
12-54 Oracle9i SQL Reference

AUDIT
Syntax
audit::=
sql_statement_clause
AUDIT
schema_object_clause
SESSION |
|
NOT |
BY |
|
|
ACCESS |
WHENEVER |
SUCCESSFUL |
;
sql_statement_clause::=
,
statement_option
ALL
auditing_by_clause
,
system_privilege
ALL PRIVILEGES
auditing_by_clause::=
,
user
, |
ON |
BEHALF |
OF |
ANY
proxy
BY ,
user
schema_object_clause::=
,
object_option
auditing_on_clause
ALL
SQL Statements: ALTER TRIGGER to COMMIT 12-55

AUDIT
auditing_on_clause::=
schema .
object
ON DIRECTORY
directory_name
DEFAULT
Semantics
sql_statement_clause
Use the sql_statement_clause to audit SQL statements.
statement_option
Specify a statement option to audit specific SQL statements.
For each audited operation, Oracle produces an audit record containing this information:
■
■
■
■
The user performing the operation
The type of operation
The object involved in the operation
The date and time of the operation
Oracle writes audit records to the audit trail, which is a database table containing audit records. You can review database activity by examining the audit trail through data dictionary views.
See Also:
■Table 12–1 on page 12-60 and Table 12–2 on page 12-62 for a list of statement options and the SQL statements they audit
■Oracle9i Database Administrator’s Guidefor a listing of the audit trail data dictionary views
■Oracle9i Database Reference for detailed descriptions of the data dictionary views
■"Auditing SQL Statements Relating to Roles: Example" on page 12-64
12-56 Oracle9i SQL Reference

AUDIT
system_privilege
Specify a system privilege to audit SQL statements that are authorized by the specified system privilege.
Rather than specifying many individual system privileges, you can specify the roles CONNECT, RESOURCE, and DBA. Doing so is equivalent to auditing all of the system privileges granted to those roles.
Oracle also provides two shortcuts for specifying groups of system privileges and statement options at once:
ALL Specify ALL to audit all statements options shown in Table 12–1 but not the additional statement options shown in Table 12–2.
ALL PRIVILEGES Specify ALL PRIVILEGES to audit system privileges.
Note: Oracle Corporation recommends that you specify individual system privileges and statement options for auditing rather than roles or shortcuts. The specific system privileges and statement options encompassed by roles and shortcuts change from one release to the next and may not be supported in future versions of Oracle.
See Also:
■Table 17–1, " System Privileges" for a list of all system privileges and the SQL statements that they authorize
■GRANT on page 17-29 for more information on the CONNECT,
RESOURCE, and DBA roles
■"Auditing Query and Update SQL Statements: Example" on page 12-65, "Auditing Deletions: Example" on page 12-65, "Auditing Statements Relating to Directories: Examples" on page 12-65
auditing_by_clause
Specify the auditing_by_clause to audit only those SQL statements issued by particular users. If you omit this clause, then Oracle audits all users’ statements.
BY user Use this clause to restrict auditing to only SQL statements issued by the specified users.
SQL Statements: ALTER TRIGGER to COMMIT 12-57

AUDIT
BY proxy Use this clause to restrict auditing to only SQL statements issued by the specified proxies.
See Also: Oracle9i Database Concepts for more information on proxies and their use of the database
ON BEHALF OF Specify user to indicate auditing of statements executed on behalf of a particular user. ANY indicates auditing of statements executed on behalf of any user.
schema_object_clause
Use the schema_object_clause to audit operations on schema objects.
object_option
Specify the particular operation for auditing. Table 12–3 on page 12-64 shows each object option and the types of objects to which it applies. The name of each object option specifies a SQL statement to be audited. For example, if you choose to audit a table with the ALTER option, then Oracle audits all ALTER TABLE statements issued against the table. If you choose to audit a sequence with the SELECT option, then Oracle audits all statements that use any of the sequence’s values.
ALL
Specify ALL as a shortcut equivalent to specifying all object options applicable for the type of object.
auditing_on_clause
The auditing_on_clause lets you specify the particular schema object to be audited.
See Also: "Auditing Queries on a Table: Example" on page 12-65, "Auditing Inserts and Updates on a Table: Example" on page 12-66, and "Auditing Operations on a Sequence: Example" on page 12-66
schema Specify the schema containing the object chosen for auditing. If you omit schema, then Oracle assumes the object is in your own schema.
object Specify the name of the object to be audited. The object must be a table, view, sequence, stored procedure, function, package, materialized view, or library.
12-58 Oracle9i SQL Reference

AUDIT
You can also specify a synonym for a table, view, sequence, procedure, stored function, package materialized view, or user-defined type.
ON DEFAULT Specify ON DEFAULT to establish the specified object options as default object options for subsequently created objects. Once you have established these default auditing options, any subsequently created object is automatically audited with those options. The default auditing options for a view are always the union of the auditing options for the view’s base tables. You can see the current default auditing options by querying the ALL_DEF_AUDIT_OPTS data dictionary view.
If you change the default auditing options, then the auditing options for previously created objects remain the same. You can change the auditing options for an existing object only by specifying the object in the ON clause of the AUDIT statement.
See Also: "Setting Default Auditing Options: Example" on page 12-66
ON DIRECTORY directory_name The ON DIRECTORY clause lets you specify the name of a directory chosen for auditing.
BY SESSION
Specify BY SESSION if you want Oracle to write a single record for all SQL statements of the same type issued and operations of the same type executed on the same schema objects in the same session.
Note: Oracle can write to an operating system audit file but cannot read it to detect whether an entry has already been written for a particular operation. Therefore, if you are using an operating system file for the audit trail (that is, the AUDIT_FILE_DEST initialization parameter is set to OS), then Oracle may write multiple records to the audit trail file even if you specify BY SESSION.
BY ACCESS
Specify BY ACCESS if you want Oracle to write one record for each audited statement and operation.
SQL Statements: ALTER TRIGGER to COMMIT 12-59

AUDIT
If you specify statement options or system privileges that audit data definition language (DDL) statements, then Oracle automatically audits by access regardless of whether you specify the BY SESSION clause or BY ACCESS clause.
For statement options and system privileges that audit SQL statements other than DDL, you can specify either BY SESSION or BY ACCESS. BY SESSION is the default.
WHENEVER [NOT] SUCCESSFUL
Specify WHENEVER SUCCESSFUL to audit only SQL statements and operations that succeed.
Specify WHENEVER NOT SUCCESSFUL to audit only statements and operations that fail or result in errors.
If you omit this clause, then Oracle performs the audit regardless of success or failure.
Tables of Auditing Options
Table 12–1 Statement Auditing Options for Database Objects
Statement Option |
SQL Statements and Operations |
|
|
CLUSTER |
CREATE CLUSTER |
|
AUDIT CLUSTER |
|
DROP CLUSTER |
|
TRUNCATE CLUSTER |
|
|
CONTEXT |
CREATE CONTEXT |
|
DROP CONTEXT |
|
|
DATABASE LINK |
CREATE DATABASE LINK |
|
DROP DATABASE LINK |
|
|
DIMENSION |
CREATE DIMENSION |
|
ALTER DIMENSION |
|
DROP DIMENSION |
|
|
DIRECTORY |
CREATE DIRECTORY |
|
DROP DIRECTORY |
|
|
INDEX |
CREATE INDEX |
|
ALTER INDEX |
|
DROP INDEX |
|
|
12-60 Oracle9i SQL Reference

AUDIT
Table 12–1 (Cont.) Statement Auditing Options for Database Objects
Statement Option |
SQL Statements and Operations |
|
|
NOT EXISTS |
All SQL statements that fail because a specified object does not |
|
exist. |
|
|
PROCEDUREa |
CREATE FUNCTION |
|
CREATE LIBRARY |
|
CREATE PACKAGE |
|
CREATE PACKAGE BODY |
|
CREATE PROCEDURE |
|
DROP FUNCTION |
|
DROP LIBRARY |
|
DROP PACKAGE |
|
DROP PROCEDURE |
|
|
PROFILE |
CREATE PROFILE |
|
ALTER PROFILE |
|
DROP PROFILE |
|
|
PUBLIC DATABASE |
CREATE PUBLIC DATABASE LINK |
LINK |
DROP PUBLIC DATABASE LINK |
|
|
|
|
PUBLIC SYNONYM |
CREATE PUBLIC SYNONYM |
|
DROP PUBLIC SYNONYM |
|
|
ROLE |
CREATE ROLE |
|
ALTER ROLE |
|
DROP ROLE |
|
SET ROLE |
|
|
ROLLBACK SEGMENT |
CREATE ROLLBACK SEGMENT |
|
ALTER ROLLBACK SEGMENT |
|
DROP ROLLBACK SEGMENT |
|
|
SEQUENCE |
CREATE SEQUENCE |
|
DROP SEQUENCE |
|
|
SESSION |
Logons |
|
|
SYNONYM |
CREATE SYNONYM |
|
DROP SYNONYM |
|
|
SYSTEM AUDIT |
AUDIT sql_statements |
|
NOAUDIT sql_statements |
|
|
SQL Statements: ALTER TRIGGER to COMMIT 12-61

AUDIT
Table 12–1 (Cont.) Statement Auditing Options for Database Objects
Statement Option |
SQL Statements and Operations |
|
|
SYSTEM GRANT |
GRANT system_privileges_and_roles |
|
REVOKE system_privileges_and_roles |
|
|
TABLE |
CREATE TABLE |
|
DROP TABLE |
|
TRUNCATE TABLE |
|
|
TABLESPACE |
CREATE TABLESPACE |
|
ALTER TABLESPACE |
|
DROP TABLESPACE |
|
|
TRIGGER |
CREATE TRIGGER |
|
ALTER TRIGGER |
|
with ENABLE and DISABLE clauses |
|
DROP TRIGGER |
|
ALTER TABLE |
|
with ENABLE ALL TRIGGERS clause |
|
and DISABLE ALL TRIGGERS clause |
|
|
TYPE |
CREATE TYPE |
|
CREATE TYPE BODY |
|
ALTER TYPE |
|
DROP TYPE |
|
DROP TYPE BODY |
|
|
USER |
CREATE USER |
|
ALTER USER |
|
DROP USER |
|
|
VIEW |
CREATE VIEW |
|
DROP VIEW |
aJava schema objects (sources, classes, and resources) are considered the same as procedures for purposes of auditing SQL statements.
Table 12–2 Additional Statement Auditing Options for SQL Statements
Statement Option |
SQL Statements and Operations |
|
|
ALTER SEQUENCE |
ALTER SEQUENCE |
|
|
12-62 Oracle9i SQL Reference

AUDIT
Table 12–2 (Cont.) Additional Statement Auditing Options for SQL Statements
Statement Option |
SQL Statements and Operations |
|
|
ALTER TABLE |
ALTER TABLE |
|
|
COMMENT TABLE |
COMMENT ON TABLE table, view, materialized view |
|
COMMENT ON COLUMN table.column, view.column, |
|
materialized view.column |
|
|
DELETE TABLE |
DELETE FROM table, view |
|
|
EXECUTE PROCEDURE |
CALL |
|
Execution of any procedure or function or access to any |
|
variable, library, or cursor inside a package. |
|
|
GRANT DIRECTORY |
GRANT privilege ON directory |
|
REVOKE privilege ON directory |
|
|
GRANT PROCEDURE |
GRANT privilege ON procedure, function, package |
|
REVOKE privilege ON procedure, function, package |
|
|
GRANT SEQUENCE |
GRANT privilege ON sequence |
|
REVOKE privilege ON sequence |
|
|
GRANT TABLE |
GRANT privilege ON table, view, materialized view. |
|
REVOKE privilege ON table, view, materialized view |
|
|
GRANT TYPE |
GRANT privilege ON TYPE |
|
REVOKE privilege ON TYPE |
|
|
INSERT TABLE |
INSERT INTO table, view |
|
|
LOCK TABLE |
LOCK TABLE table, view |
|
|
SELECT SEQUENCE |
Any statement containing sequence.CURRVAL or |
|
sequence.NEXTVAL |
|
|
SELECT TABLE |
SELECT FROM table, view, materialized view |
|
|
UPDATE TABLE |
UPDATE table, view |
|
|
SQL Statements: ALTER TRIGGER to COMMIT 12-63

AUDIT
Table 12–3 Object Auditing Options
|
|
|
|
Procedure, |
|
|
|
|
|
Object |
|
|
|
Function, |
Material- |
|
|
Object |
|
|
|
|
Packagea |
|
|
|
|
||
Option |
Table |
View |
Sequence |
ized View |
Directory |
Library |
Type |
Context |
|
ALTER |
X |
— |
X |
— |
X |
— |
— |
X |
— |
|
|
|
|
|
|
|
|
|
|
AUDIT |
X |
X |
X |
X |
X |
X |
— |
X |
X |
|
|
|
|
|
|
|
|
|
|
COMMENT |
X |
X |
— |
— |
X |
— |
— |
— |
— |
|
|
|
|
|
|
|
|
|
|
DELETE |
X |
X |
— |
— |
X |
— |
— |
— |
— |
|
|
|
|
|
|
|
|
|
|
EXECUTE |
— |
— |
— |
X |
— |
— |
X |
— |
— |
|
|
|
|
|
|
|
|
|
|
GRANT |
X |
X |
X |
X |
— |
X |
X |
X |
X |
|
|
|
|
|
|
|
|
|
|
INDEX |
X |
— |
— |
— |
X |
— |
— |
— |
— |
|
|
|
|
|
|
|
|
|
|
INSERT |
X |
X |
— |
— |
X |
— |
— |
— |
— |
|
|
|
|
|
|
|
|
|
|
LOCK |
X |
X |
— |
— |
X |
— |
— |
— |
— |
|
|
|
|
|
|
|
|
|
|
READ |
— |
— |
— |
— |
— |
X |
— |
— |
— |
|
|
|
|
|
|
|
|
|
|
RENAME |
X |
X |
— |
X |
X |
— |
— |
— |
— |
|
|
|
|
|
|
|
|
|
|
SELECT |
X |
X |
X |
— |
X |
— |
— |
— |
— |
|
|
|
|
|
|
|
|
|
|
UPDATE |
X |
X |
— |
— |
X |
— |
— |
— |
— |
a Java schema objects (sources, classes, and resources) are considered the same as procedures, functions, and packages for purposes of auditing options.
Examples
Auditing SQL Statements Relating to Roles: Example To choose auditing for every SQL statement that creates, alters, drops, or sets a role, regardless of whether the statement completes successfully, issue the following statement:
AUDIT ROLE;
To choose auditing for every statement that successfully creates, alters, drops, or sets a role, issue the following statement:
AUDIT ROLE
WHENEVER SUCCESSFUL;
12-64 Oracle9i SQL Reference

AUDIT
To choose auditing for every CREATE ROLE, ALTER ROLE, DROP ROLE, or SET ROLE statement that results in an Oracle error, issue the following statement:
AUDIT ROLE
WHENEVER NOT SUCCESSFUL;
Auditing Query and Update SQL Statements: Example To choose auditing for any statement that queries or updates any table, issue the following statement:
AUDIT SELECT TABLE, UPDATE TABLE;
To choose auditing for statements issued by the users hr and oe that query or update a table or view, issue the following statement:
AUDIT SELECT TABLE, UPDATE TABLE
BY hr, oe;
Auditing Deletions: Example To choose auditing for statements issued using the DELETE ANY TABLE system privilege, issue the following statement:
AUDIT DELETE ANY TABLE;
Auditing Statements Relating to Directories: Examples To choose auditing for statements issued using the CREATE ANY DIRECTORY system privilege, issue the following statement:
AUDIT CREATE ANY DIRECTORY;
To choose auditing for CREATE DIRECTORY (and DROP DIRECTORY) statements that do not use the CREATE ANY DIRECTORY system privilege, issue the following statement:
AUDIT DIRECTORY;
To choose auditing for every statement that reads files from the bfile_dir directory, issue the following statement:
AUDIT READ ON DIRECTORY bfile_dir;
Auditing Queries on a Table: Example To choose auditing for every SQL statement that queries the employees table in the schema hr, issue the following statement:
AUDIT SELECT
ON hr.employees;
SQL Statements: ALTER TRIGGER to COMMIT 12-65

AUDIT
To choose auditing for every statement that successfully queries the employees table in the schema hr, issue the following statement:
AUDIT SELECT
ON hr.employees
WHENEVER SUCCESSFUL;
To choose auditing for every statement that queries the employees table in the schema hr and results in an Oracle error, issue the following statement:
AUDIT SELECT
ON hr.employees
WHENEVER NOT SUCCESSFUL;
Auditing Inserts and Updates on a Table: Example To choose auditing for every statement that inserts or updates a row in the customers table in the schema oe, issue the following statement:
AUDIT INSERT, UPDATE
ON oe.customers;
Auditing Operations on a Sequence: Example To choose auditing for every statement that performs any operation on the employees_seq sequence in the schema hr, issue the following statement:
AUDIT ALL
ON hr.employees_seq;
The preceding statement uses the ALL shortcut to choose auditing for the following statements that operate on the sequence:
■ALTER SEQUENCE
■AUDIT
■GRANT
■any statement that accesses the sequence’s values using the pseudocolumns
CURRVAL or NEXTVAL
Setting Default Auditing Options: Example The following statement specifies default auditing options for objects created in the future:
AUDIT ALTER, GRANT, INSERT, UPDATE, DELETE
ON DEFAULT;
12-66 Oracle9i SQL Reference

AUDIT
Any objects created later are automatically audited with the specified options that apply to them, if auditing has been enabled:
■If you create a table, then Oracle automatically audits any ALTER, GRANT, INSERT, UPDATE, or DELETE statements issued against the table.
■If you create a view, then Oracle automatically audits any GRANT, INSERT, UPDATE, or DELETE statements issued against the view.
■If you create a sequence, then Oracle automatically audits any ALTER or GRANT statements issued against the sequence.
■If you create a procedure, package, or function, then Oracle automatically audits any ALTER or GRANT statements issued against it.
SQL Statements: ALTER TRIGGER to COMMIT 12-67