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

SQL Overview

SQL Overview

SQL is a database access, nonprocedural language. Users describe in SQL what they want done, and the SQL language compiler automatically generates a procedure to navigate the database and perform the desired task.

IBM Research developed and defined SQL, and ANSI/ISO has refined SQL as the standard language for relational database management systems.The minimal conformance level for SQL-99 is known as Core. Core SQL-99 is a superset of SQL-92 Entry Level specification. Oracle9i is broadly compatible with the SQL-99 Core specification.

Oracle SQL includes many extensions to the ANSI/ISO standard SQL language, and Oracle tools and applications provide additional statements. The Oracle tools SQL*Plus and Oracle Enterprise Manager let you run any ANSI/ISO standard SQL statement against an Oracle database, as well as additional statements or functions that are available for those tools.

Oracle SQLJ lets applications programmers embed static SQL operations in Java code in a way that is compatible with the Java design philosophy. A SQLJ program is a Java program containing embedded static SQL statements that comply with the ANSI-standard SQLJ Language Reference syntax.

Although some Oracle tools and applications simplify or mask SQL use, all database operations are performed using SQL. Any other data access method circumvents the security built into Oracle and potentially compromise data security and integrity.

See Also:

Oracle9i SQL Reference for detailed information about SQL statements and other parts of SQL (such as operators, functions, and format models)

Oracle Enterprise Manager Administrator’s Guide

SQL*Plus User’s Guide and Reference for SQL*Plus statements, including their distinction from SQL statements

Oracle9i SQLJ Developer’s Guide and Reference for information about embedding SQL operations in Java code

SQL Statements

All operations performed on the information in an Oracle database are run using SQL statements. A statement consists partially of SQL reserved words, which have

14-2 Oracle9i Database Concepts

SQL Overview

special meaning in SQL and cannot be used for any other purpose. For example, SELECT and UPDATE are reserved words and cannot be used as table names.

A SQL statement is a computer program or instruction. The statement must be the equivalent of a complete SQL sentence, as in:

SELECT last_name, department_id FROM employees;

Only a complete SQL statement can be run. A fragment such as the following generates an error indicating that more text is required before a SQL statement can run:

SELECT last_name

Oracle SQL statements are divided into the following categories:

Data Manipulation Language Statements

Data Definition Language Statements

Transaction Control Statements

Session Control Statements

System Control Statements

Embedded SQL Statements

See Also: Chapter 17, "Triggers" for more information about using SQL statements in PL/SQL program units

Data Manipulation Language Statements

Data manipulation language (DML) statements query or manipulate data in existing schema objects. They enable you to:

Retrieve data from one or more tables or views (SELECT); fetches can be scrollable (see "Scrollable Cursors" on page 14-7)

Add new rows of data into a table or view (INSERT)

Change column values in existing rows of a table or view (UPDATE)

Update or insert rows conditionally into a table or view (MERGE)

Remove rows from tables or views (DELETE)

See the execution plan for a SQL statement (EXPLAIN PLAN)

Lock a table or view, temporarily limiting other users’ access (LOCK TABLE)

SQL, PL/SQL, and Java 14-3

SQL Overview

DML statements are the most frequently used SQL statements. Some examples of DML statements are:

SELECT last_name, manager_id, commission_pct + salary FROM employees;

INSERT INTO employees VALUES

(1234, ’DAVIS’, ’SALESMAN’, 7698, ’14-FEB-1988’, 1600, 500, 30);

DELETE FROM employees WHERE last_name IN (’WARD’,’JONES’);

Data Definition Language Statements

Data definition language (DDL) statements define, alter the structure of, and drop schema objects. DDL statements enable you to:

Create, alter, and drop schema objects and other database structures, including the database itself and database users (CREATE, ALTER, DROP)

Change the names of schema objects (RENAME)

Delete all the data in schema objects without removing the objects’ structure (TRUNCATE)

Grant and revoke privileges and roles (GRANT, REVOKE)

Turn auditing options on and off (AUDIT, NOAUDIT)

Add a comment to the data dictionary (COMMENT)

DDL statements implicitly commit the preceding and start a new transaction. Some examples of DDL statements are:

CREATE TABLE plants

(COMMON_NAME VARCHAR2 (15), LATIN_NAME VARCHAR2 (40));

DROP TABLE plants;

GRANT SELECT ON employees TO scott;

REVOKE DELETE ON employees FROM scott;

See Also:

Chapter 22, "Controlling Database Access"

Chapter 23, "Privileges, Roles, and Security Policies"

Chapter 24, "Auditing"

14-4 Oracle9i Database Concepts

SQL Overview

Transaction Control Statements

Transaction control statements manage the changes made by DML statements and group DML statements into transactions. They enable you to:

Make a transaction’s changes permanent (COMMIT)

Undo the changes in a transaction, either since the transaction started or since a savepoint (ROLLBACK)

Set a point to which you can roll back (SAVEPOINT)

Establish properties for a transaction (SET TRANSACTION)

Session Control Statements

Session control statements manage the properties of a particular user’s session. For example, they enable you to:

Alter the current session by performing a specialized function, such as enabling and disabling the SQL trace facility (ALTER SESSION)

Enable and disable roles (groups of privileges) for the current session (SET ROLE)

System Control Statements

System control statements change the properties of the Oracle server instance. The only system control statement is ALTER SYSTEM. It enables you to change settings (such as the minimum number of shared servers), kill a session, and perform other tasks.

Embedded SQL Statements

Embedded SQL statements incorporate DDL, DML, and transaction control statements within a procedural language program. They are used with the Oracle precompilers. Embedded SQL statements enable you to:

Define, allocate, and release cursors (DECLARE CURSOR, OPEN, CLOSE)

Specify a database and connect to Oracle (DECLARE DATABASE, CONNECT)

Assign variable names (DECLARE STATEMENT)

Initialize descriptors (DESCRIBE)

Specify how error and warning conditions are handled (WHENEVER)

Parse and run SQL statements (PREPARE, EXECUTE, EXECUTE IMMEDIATE)

SQL, PL/SQL, and Java 14-5

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