Docsity

Structured Query Language Statements - Database Systems | CSCI 585, Study notes of Deductive Database Systems

Partial preview of the text

Download Structured Query Language Statements - Database Systems | CSCI 585 and more Study notes Deductive Database Systems in PDF only on Docsity!

Oracle® Database

SQL Quick Reference

10 g Release 1 (10.1)

Part No. B10758-

December 2003

Oracle Database SQL Quick Reference, 10 g Release 1 (10.1)

Part No. B10758-

Copyright © 2003 Oracle Corporation. All rights reserved.

Contributors: Joan Gregoire, Diana Lorentz, Simon Watt

The Programs (which include both the software and documentation) contain proprietary information of Oracle Corporation; they are provided under a license agreement containing restrictions on use and disclosure and are also protected by copyright, patent and other intellectual and industrial property laws. Reverse engineering, disassembly or decompilation of the Programs, except to the extent required to obtain interoperability with other independently created software or as specified by law, is prohibited.

The information contained in this document is subject to change without notice. If you find any problems in the documentation, please report them to us in writing. Oracle Corporation does not warrant that this document is error-free. Except as may be expressly permitted in your license agreement for these Programs, no part of these Programs may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Oracle Corporation.

If the Programs are delivered to the U.S. Government or anyone licensing or using the programs on behalf of the U.S. Government, the following notice is applicable:

Restricted Rights Notice Programs delivered subject to the DOD FAR Supplement are "commercial computer software" and use, duplication, and disclosure of the Programs, including documentation, shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement. Otherwise, Programs delivered subject to the Federal Acquisition Regulations are "restricted computer software" and use, duplication, and disclosure of the Programs shall be subject to the restrictions in FAR 52.227-19, Commercial Computer Software - Restricted Rights (June, 1987). Oracle Corporation, 500 Oracle Parkway, Redwood City, CA 94065.

The Programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently dangerous applications. It shall be the licensee's responsibility to take all appropriate fail-safe, backup, redundancy, and other measures to ensure the safe use of such applications if the Programs are used for such purposes, and Oracle Corporation disclaims liability for any damages caused by such use of the Programs.

Oracle is a registered trademark, and Oracle Store, PL/SQL, SQLPlus, and iSQLPlus are trademarks or registered trademarks of Oracle Corporation. Other names may be trademarks of their respective owners.

iv

6 Datatypes

Datatypes .............................................................................................................................................. 6-

Oracle Built-In Datatypes ............................................................................................................ 6-

Converting to Oracle Datatypes ................................................................................................. 6-

7 Format Models

Format Models ..................................................................................................................................... 7-

Number Format Models .............................................................................................................. 7-

Number Format Elements .................................................................................................... 7-

Datetime Format Models ............................................................................................................. 7-

Datetime Format Elements................................................................................................... 7-

A SQL*Plus Commands

SQL*Plus Commands ......................................................................................................................... A-

Index

v

Send Us Your Comments

Oracle Database SQL Quick Reference, 10 g Release 1 (10.1)

Part No. B10758-

Oracle Corporation welcomes your comments and suggestions on the quality and usefulness of this

publication. Your input is an important part of the information used for revision.

 Did you find any errors?

 Is the information clearly presented?

 Do you need more information? If so, where?

 Are the examples correct? Do you need more examples?

 What features did you like most about this manual?

If you find any errors or have any other suggestions for improvement, please indicate the title and

part number of the documentation and the chapter, section, and page number (if available). You can

send comments to us in the following ways:

 Electronic mail: [email protected]

 FAX: (650) 506-7227 Attn: Server Technologies Documentation Manager

 Postal service:

Oracle Corporation

Oracle Server Technologies Documentation

500 Oracle Parkway, Mailstop 4op

Redwood Shores, CA 94065

U.S.A.

If you would like a reply, please give your name, address, telephone number, and (optionally) your

electronic mail address.

If you have problems with the software, please contact your local Oracle Support Services.

vii

Preface

This quick reference contains a high-level description of the Structured Query

Language (SQL) used to manage information in an Oracle database. Oracle SQL is a

superset of the American National Standards Institute (ANSI) and the International

Standards Organization (ISO) SQL:2003 standard.

This preface contains these topics:

 Audience

 Organization

 Related Documentation

 Conventions

 Documentation Accessibility

Audience

Oracle Database SQL Quick Reference is intended for all users of Oracle SQL.

Organization

This quick reference is divided into the following parts:

Chapter 1, "SQL Statements"

This chapter presents the syntax for Oracle SQL statements.

Chapter 2, "SQL Functions"

This chapter presents the syntax for SQL functions.

viii

Chapter 3, "SQL Expressions"

This chapter presents the syntax for SQL expressions.

Chapter 4, "SQL Conditions"

This chapter presents the syntax for SQL conditions.

Chapter 5, "Subclauses"

This chapter presents the syntax for all subclauses found in Chapters 1 through 4.

Chapter 6, "Datatypes"

This chapter presents datatypes recognized by Oracle and available for use within

SQL.

Chapter 7, "Format Models"

This chapter presents the format models for datetime and number data stored in

character strings.

Appendix A, "SQL*Plus Commands"

This appendix presents the basic SQL*Plus commands.

Related Documentation

For more information, see these Oracle resources:

 Oracle Database SQL Reference

 PL/SQL User's Guide and Reference

 SQL*Plus User's Guide and Reference

Printed documentation is available for sale in the Oracle Store at

http://oraclestore.oracle.com/

To download free release notes, installation documentation, white papers, or other

collateral, please visit the Oracle Technology Network (OTN). You must register

online before using OTN; registration is free and can be done at

http://otn.oracle.com/membership/

If you already have a username and password for OTN, then you can go directly to

the documentation section of the OTN Web site at

x

Conventions in Code Examples

Code examples illustrate SQL, PL/SQL, SQL*Plus, or other command-line

statements. They are displayed in a monospace (fixed-width) font and separated

from normal text as shown in this example:

SELECT username FROM dba_users WHERE username = 'MIGRATE';

The following table describes typographic conventions used in code examples and

provides examples of their use.

lowercase monospace (fixed-width) font

Lowercase monospace typeface indicates executables, filenames, directory names, and sample user-supplied elements. Such elements include computer and database names, net service names, and connect identifiers, as well as user-supplied database objects and structures, column names, packages and classes, usernames and roles, program units, and parameter values. Note: Some programmatic elements use a mixture of UPPERCASE and lowercase. Enter these elements as shown.

Enter sqlplus to open SQL*Plus. The password is specified in the orapwd file. Back up the datafiles and control files in the /disk1/oracle/dbs directory. The department_id, department_name, and location_id columns are in the hr.departments table. Set the QUERY_REWRITE_ENABLED initialization parameter to true. Connect as oe user. The JRepUtil class implements these methods.

lowercase italic monospace (fixed-width) font

Lowercase italic monospace font represents placeholders or variables.

You can specify the parallel_clause. Run U old_release .SQL where old release_ refers to the release you installed prior to upgrading.

Convention Meaning Example

[ ] Brackets enclose one or more optional items. Do not enter the brackets.

DECIMAL ( digits [ , precision ])

{ } Braces enclose two or more items, one of which is required. Do not enter the braces.

{ENABLE | DISABLE}

| A vertical bar represents a choice of two or more options within brackets or braces. Enter one of the options. Do not enter the vertical bar.

{ENABLE | DISABLE}

[COMPRESS | NOCOMPRESS]

Convention Meaning Example

xi

... Horizontal ellipsis points indicate either:

 That we have omitted parts of the code that are not directly related to the example  That you can repeat a portion of the code

CREATE TABLE ... AS subquery ;

SELECT col1 , col2 , ... , coln FROM employees;

Vertical ellipsis points indicate that we have omitted several lines of code not directly related to the example.

SQL> SELECT NAME FROM V$DATAFILE;

NAME

/fsl/dbs/tbs_01.dbf /fs1/dbs/tbs_02.dbf . . . /fsl/dbs/tbs_09.dbf 9 rows selected.

Other notation You must enter symbols other than brackets, braces, vertical bars, and ellipsis points as shown.

acctbal NUMBER(11,2); acct CONSTANT NUMBER(4) := 3;

Italics Italicized text indicates placeholders or variables for which you must supply particular values.

CONNECT SYSTEM/ system_password DB_NAME = database_name

UPPERCASE Uppercase typeface indicates elements supplied by the system. We show these terms in uppercase in order to distinguish them from terms you define. Unless terms appear in brackets, enter them in the order and with the spelling shown. However, because these terms are not case sensitive, you can enter them in lowercase.

SELECT last_name, employee_id FROM employees; SELECT * FROM USER_TABLES; DROP TABLE hr.employees;

lowercase Lowercase typeface indicates programmatic elements that you supply. For example, lowercase indicates names of tables, columns, or files. Note: Some programmatic elements use a mixture of UPPERCASE and lowercase. Enter these elements as shown.

SELECT last_name, employee_id FROM employees; sqlplus hr/hr CREATE USER mjones IDENTIFIED BY ty3MU9;

Convention Meaning Example

SQL Statements 1-

SQL Statements

This chapter presents the syntax for Oracle SQL statements.

This chapter includes the following section:

 Syntax for SQL Statements

Syntax for SQL Statements

SQL statements are the means by which programs and users access data in an

Oracle database.

Table 1–1 shows each SQL statement and its related syntax. Refer to Chapter 5,

"Subclauses" for the syntax of the subclauses found in the following table.

See Also: Oracle Database SQL Reference for detailed information

about Oracle SQL

Syntax for SQL Statements

1-2 Oracle Database SQL Quick Reference

Table 1–1 Syntax for SQL Statements

SQL Statement Syntax

ALTER CLUSTER ALTER CLUSTER [ schema. ]cluster { physical_attributes_clause | SIZE size_clause | allocate_extent_clause | deallocate_unused_clause | { CACHE | NOCACHE } } [ physical_attributes_clause | SIZE size_clause | allocate_extent_clause | deallocate_unused_clause | { CACHE | NOCACHE } ]... [ parallel_clause ] ;

ALTER DATABASE ALTER DATABASE [ database ] { startup_clauses | recovery_clauses | database_file_clauses | logfile_clauses | controlfile_clauses | standby_database_clauses | default_settings_clauses | redo_thread_clauses | security_clause } ;

Syntax for SQL Statements

1-4 Oracle Database SQL Quick Reference

ALTER INDEX ALTER INDEX [ schema. ]index { { deallocate_unused_clause | allocate_extent_clause | shrink_clause | parallel_clause | physical_attributes_clause | logging_clause } [ deallocate_unused_clause | allocate_extent_clause | shrink_clause | parallel_clause | physical_attributes_clause | logging_clause ]... | rebuild_clause | PARAMETERS ('ODCI_parameters') | { ENABLE | DISABLE } | UNUSABLE | RENAME TO new_name | COALESCE | { MONITORING | NOMONITORING } USAGE | UPDATE BLOCK REFERENCES | alter_index_partitioning } ;

ALTER INDEXTYPE ALTER INDEXTYPE [ schema. ]indextype { { ADD | DROP } [ schema. ]operator (parameter_types) [, { ADD | DROP } [ schema. ]operator (parameter_types) ]... [ using_type_clause ] | COMPILE } ;

ALTER JAVA ALTER JAVA { SOURCE | CLASS } [ schema. ]object_name [ RESOLVER ( ( match_string [, ] { schema_name | - } ) [ ( match_string [, ] { schema_name | - } ) ]... ) ] { { COMPILE | RESOLVE } | invoker_rights_clause } ;

Table 1–1 (Cont.) Syntax for SQL Statements

SQL Statement Syntax

Syntax for SQL Statements

SQL Statements 1-

ALTER MATERIALIZED VIEW ALTER MATERIALIZED VIEW schema. [ physical_attributes_clause | table_compression | LOB_storage_clause [, LOB_storage_clause ]... | modify_LOB_storage_clause [, modify_LOB_storage_clause ]... | alter_table_partitioning | parallel_clause | logging_clause | allocate_extent_clause | shrink_clause | { CACHE | NOCACHE } ] [ alter_iot_clauses ] [ USING INDEX physical_attributes_clause ] [ MODIFY scoped_table_ref_constraint | alter_mv_refresh ] [ { ENABLE | DISABLE } QUERY REWRITE | COMPILE | CONSIDER FRESH ] ;

Table 1–1 (Cont.) Syntax for SQL Statements

SQL Statement Syntax

Syntax for SQL Statements

SQL Statements 1-

ALTER OUTLINE ALTER OUTLINE [ PUBLIC | PRIVATE ] outline { REBUILD | RENAME TO new_outline_name | CHANGE CATEGORY TO new_category_name | { ENABLE | DISABLE } } [ REBUILD | RENAME TO new_outline_name | CHANGE CATEGORY TO new_category_name | { ENABLE | DISABLE } ]... ;

ALTER PACKAGE ALTER PACKAGE [ schema. ]package COMPILE [ DEBUG ] [ PACKAGE | SPECIFICATION | BODY ] [ compiler_parameters_clause [ compiler_parameters_clause ] ... ] [ REUSE SETTINGS ] ;

ALTER PROCEDURE ALTER PROCEDURE [ schema. ]procedure COMPILE [ DEBUG ] [ compiler_parameters_clause [ compiler_parameters_clause ] ... ] [ REUSE SETTINGS ] ;

ALTER PROFILE ALTER PROFILE profile LIMIT { resource_parameters | password_parameters } [ resource_parameters | password_parameters ]... ;

ALTER RESOURCE COST ALTER RESOURCE COST { CPU_PER_SESSION | CONNECT_TIME | LOGICAL_READS_PER_SESSION | PRIVATE_SGA } integer [ { CPU_PER_SESSION | CONNECT_TIME | LOGICAL_READS_PER_SESSION | PRIVATE_SGA } integer ] ... ;

Table 1–1 (Cont.) Syntax for SQL Statements

SQL Statement Syntax

Syntax for SQL Statements

1-8 Oracle Database SQL Quick Reference

ALTER ROLE ALTER ROLE role { NOT IDENTIFIED | IDENTIFIED { BY password | USING [ schema. ]package | EXTERNALLY | GLOBALLY } } ;

ALTER ROLLBACK SEGMENT ALTER ROLLBACK SEGMENT rollback_segment { ONLINE | OFFLINE | storage_clause | SHRINK [ TO integer [ K | M ] ] };

ALTER SEQUENCE ALTER SEQUENCE [ schema. ]sequence { INCREMENT BY integer | { MAXVALUE integer | NOMAXVALUE } | { MINVALUE integer | NOMINVALUE } | { CYCLE | NOCYCLE } | { CACHE integer | NOCACHE } | { ORDER | NOORDER } } [ INCREMENT BY integer | { MAXVALUE integer | NOMAXVALUE } | { MINVALUE integer | NOMINVALUE } | { CYCLE | NOCYCLE } | { CACHE integer | NOCACHE } | { ORDER | NOORDER } ]... ;

ALTER SESSION ALTER SESSION { ADVISE { COMMIT | ROLLBACK | NOTHING } | CLOSE DATABASE LINK dblink | { ENABLE | DISABLE } COMMIT IN PROCEDURE | { ENABLE | DISABLE } GUARD | { ENABLE | DISABLE | FORCE } PARALLEL { DML | DDL | QUERY } [ PARALLEL integer ] | { ENABLE RESUMABLE [ TIMEOUT integer ] [ NAME string ] | DISABLE RESUMABLE } | alter_session_set_clause } ;

Table 1–1 (Cont.) Syntax for SQL Statements

SQL Statement Syntax