Академический Документы
Профессиональный Документы
Культура Документы
ANKUR RAINA
CONTENTS
1. Introduction to Oracle RDBMS
1.1.Features 1.2.Oracle Internet Platform
3
3 4
2. E.F.Codds Rules 2.1 Rules 2.2 Satisfied by Oracle RDBMS 3. Oracle Database Architecture
3.1. The Database 3.2. The Instance
5 5 6
8 9 11
4. SQL Statements
4.1.Types 4.2. Capabilities of SQL SELECT Statements 4.3.Data Retrieval Using SELECT Statement 4.4.Defining a NULL value 4.5.Defining a Column Alias 4.6.Restricting and Sorting Statements
14
14 15 15 16 17 17
18
22 22 24 25
6. Reporting Aggregating Data Using Group Functions 6.1. Group Function 6.2. Creating Groups of Data: GROUP BY clause syntax 6.3. Using GROUP BY clause for multiple columns 6.4. Restricting Group Results by HAVING clause 7. Displaying Data From Multiple Tables
7.1 Using Subqueries to Solve Queries
26
26 27 28 28
29
30
ANKUR RAINA
09-IT-4505
8. Manipulating Data 8.1. INSERT statement 8.2. UPDATE statement 8.3. DELETE statement 9. Database Objects
31 31
32 32 32
8.4. TRUNCATE statement 9.1. CREATE statement 9.2. CREATE TABLE using a sub-query 9.3. Dropping a table
34
34 35 35 36 36 36 37 37 38 39
10.Creating Other Schema Objects 10.1. Views 10.2.Creating views 10.3.Sequence 10.4.Indexes 10.5.Synonyms 11.References
ANKUR RAINA
09-IT-4505
CHAPTER 1
Our goal is very simply to become the desktop for e-businesses - Larry Ellison
Introduction to Oracle RDBMS
The Oracle Database (commonly referred to as Oracle RDBMS or simply as Oracle) is an object-relational database management system (ORDBMS) produced and marketed by Oracle Corporation. Larry Ellison and his friends and former co-workers Bob Miner and Ed Oates started the consultancy Software Development Laboratories (SDL) in 1977. SDL developed the original version of the Oracle software. The name Oracle comes from the code-name of a CIA-funded project Ellison had worked on while previously employed by Ampex. The latest release of Oracle RDBMS is 11g Release 2.
Features:-
ANKUR RAINA
09-IT-4505
ANKUR RAINA
09-IT-4505
E.F. Codd, the famous mathematician has introduced 12 rules for the relational model for databases commonly known as Codd's rules. The rules mainly define what is required for a DBMS for it to be considered relational, i.e., an RDBMS. There is also one more rule i.e. Rule00 which specifies the relational model should use the relational way to manage the database. The rules and their description are as follows:-
Rules:
Rule 000: Zeroth rule: An RDBMS system should be capable of using its relational facilities (exclusively) to manage the database. Rule 1: The information rule: All information in the database is to be represented in one and only one way. This is achieved by values in column positions within rows of tables. Rule 2: The guaranteed access rule: All data must be accessible with no ambiguity. This is achieved in the RDBMS by using the primary key concept. Rule 3: Systematic treatment of null values: The DBMS must allow each field to remain null. The null can be stored in any field of any datatype. Rule 4: Active online catalog based on the relational model: The authorized users can access the database structure by using common language i.e. SQL. Rule 5: The comprehensive data sublanguage rule: The system must support at least one relational language that has simple syntax and transaction management facilities. It can be used in the application as well as in the RDBMS systems.
ANKUR RAINA
09-IT-4505
Rule 6: The view updating rule: All views must be updatable by the system.
Rule 7: High-level insert, update, and delete: The system is able to insert, update and delete operations fully. It can also perform the operations on multiple rows simultaneously. Rule 8: Physical data independence: Changes to the physical storage structure must not require a change to an application based on the structure. Rule 9: Logical data independence: Changes to the logical level (tables, columns, rows, and so on) must not require a change to an application based on the structure. Rule 11: Distribution independence: The distribution of portions of the database to various locations should be invisible to users of the database. Rule 12: The non- subversion rule: If the system provides a low-level (record-at-a-time) interface, then that interface cannot be used to subvert the system, for example, bypassing a relational security or integrity constraint. Note:- Any database management system which fulfills 6 or more than 6 rules can be considered as the RDBMS.
ANKUR RAINA
09-IT-4505
2. Systematic Treatment of Null value Null in Oracle is treated as absence of a value or unknown status ( in case of comparison of values ) and it does not have any systematic representation. In Oracle, no two null values are equal (as this will return a value which is treated as unknown by Oracle). If there is a systematic representation, then NULL value must be comparable.
ANKUR RAINA
09-IT-4505
Control Files:
These files contain data about the database itself, called the metadata. These files are critical to the database. Without them, one cannot open the data files to access the data within the database.
Data Files:
These files contain the data of the database.
ANKUR RAINA
09-IT-4505
ANKUR RAINA
09-IT-4505
A database is divided into logical storage units called tablespaces, which can be used to group related logical structures. Each database is logically divided into one or more tablespaces. One or more data files are explicitly created for each tablespace to physically store the data of all logical structures in a tablespace.
When the database requests a set of data blocks from the operating system (OS), the OS maps this to the actual OS block on the storage device. Because of this, one needs not to be aware of the physical address of any data in the database. This also means that a data file can be striped and or mirrored on several disks. The size of the data block can be set at database creation time. The default size of 8K is adequate for more databases. If your database supports a data warehouse application that has large tables and indexes, then a larger block may be beneficial. If your database supports a transactional application where reads and writes are very random, then a smaller block size may be beneficial. The maximum block size is dependent on the OS. The minimum block size is 2K and should rarely (if ever) be used. There are other files that are not officially part of the database, but are important to the successful running of the database. These are:
Parameter File:
The parameter file is used to define how the instance will be configured when it starts up.
ANKUR RAINA
09-IT-4505
Password File:
This file allows users to connect remotely to the database and perform administrative tasks.
An Oracle Database server consists of an Oracle Database and an Oracle instance. An Oracle instance consists of memory buffers known as the System Global Area (SGA) and background processes. The instance is idle (non-existent) until it is started. When the instance is started, an initialization parameter file is read and the instance is configured accordingly. After the instance is started and the database is opened, users can access the database.
ANKUR RAINA
09-IT-4505
The SGA is a shared memory area that contains data and control information for the instance. The SGA consists of the following data structures: Database buffer cache: Caches blocks of data retrieved from the database. Redo log buffer: Caches redo information (used for instance recovery) until it can be written to the physical redo log files stored on disk. Shared pool: Caches various constructs that can be shared among users. Large pool: Is an optional area used for buffering large I/O requests. Java pool: Is used for all session-specific Java code and data within the Java Virtual Machine (JVM).
ANKUR RAINA 09-IT-4505
Stream pool: Is used by Oracle Streams. When we start the instance by using Enterprise Manager or SQL*Plus, the memory allocated for the SGA is displayed. A PGA is a memory region that contains data and control information for each server process. A server process services a clients requests. Each server process has its own private PGA area that is created when the server process is started. Access to it is exclusive to that is created when the server process is started. Access to it is exclusive to that server process, and is read and written only by the oracle code acting on behalf of it. The amount of PGA memory used and its content depends on whether the instance is configured in shared mode. Generally, the PGA contains the following:
Private SQL area: Contains data such as bind information and run-time memory
structures. Each session that issues a SQL statement has a private SQL area.
Session memory: Is memory allocated to hold session variables and other information
related to the session.
ANKUR RAINA
09-IT-4505
ANKUR RAINA
09-IT-4505
Transaction Control:
A discrete unit of work that must be completely processed or not processed at all within a computer system is called a transaction. The following commands control the transactions. COMMIT ROLLBACK SAVEPOINT
Projection: To choose the columns in a table that is returned by a query. Selection: To choose the rows in a table that is returned by a query. Various criteria can be
used to restrict the rows that are retrieved.
Joining: To bring together data that is stored in different tables by specifying the link
between them.
SELECT identifies the columns to be displayed. FROM identifies the table containing those columns.
If all columns are of data in a table are to be listed, an asterisk (*) can be used.
ANKUR RAINA 09-IT-4505
...
ANKUR RAINA
09-IT-4505
Character Strings and Dates: Character strings and date values are enclosed in single quotation marks. Character strings are case sensitive, and date values are format sensitive. The default date format is DD-MON-RR.
ANKUR RAINA
09-IT-4505
Comparison Conditions:
ANKUR RAINA
09-IT-4505
Logical Conditions:
ANKUR RAINA
09-IT-4505
Rules of Precedence
Sorting Data:
Sort retrieved rows with the ORDER BY clause: 1. ASC: ascending order, default 2. DESC: descending order The ORDER BY clause comes last in the SELECT statement.
ANKUR RAINA
09-IT-4505
Use the double ampersand (&&) if you want to reuse the variable value without prompting the user each time.
ANKUR RAINA
09-IT-4505
General Functions:
FUNCTION NVL NVL2 SYNTAX NVL(expr1,expr2) NVL2(expr1,expr2,expr3) DESCRIPTION Converts a null value to actual value.
I f expr1 is not null, NVL2 returns expr2. If expr1 is null, NVL2 returns expr3. Compares two expressions NULLIF and returns null if they are NULLIF(expr1,expr2) equal; returns the first expression if they are not equal. Returns the first non-null COALESCE COALESCE(expr1,expr2,...,exprn) expression in the expression list.
ANKUR RAINA
09-IT-4505
USING NVL:
USING NVL2:
USING NULLIF:
USING COALESCE:
ANKUR RAINA
09-IT-4505
CASE Expression:
It facilitates conditional inquiries by doing the work of an IF-THEN_ELSE statement.
ANKUR RAINA
09-IT-4505
DECODE Function:
It facilitates conditional inquiries by doing the work of a CASE expression or IF-THEN-ELSE statement.
ANKUR RAINA
09-IT-4505
FUNCTION
AVG COUNT
SYNTAX
AVG([DISTINCT|ALL]n)
DESCRIPTION
Average value of n, ignoring null values. COUNT({*|[DISTINCT|ALL]expr}) No. of rows where expr evaluates to something other than null(count all selected rows using * , including duplicates and rows with nulls) MAX([DISTINCT|ALL]expr) Max value of expr ignoring null values MIN([DISTINCT|ALL]expr) Min value of expr ignoring null values STDDEV([DISTINCT|ALL]x) Standard deviation of n ignoring null values SUM([DISTINCT|ALL]n) Sum values of n ignoring null values VARIANCE([DISTINCT|ALL]x) Variance of n ignoring null values
ANKUR RAINA
09-IT-4505
COUNT (expr) returns the number of rows with non-null values for expr.
COUNT (DISTINCT expr) returns the number of distinct non-null values of expr.
ANKUR RAINA
09-IT-4505
ANKUR RAINA
09-IT-4505
If several columns have the same names but the data types do not match, natural join can be applied by using the USING clause to specify the columns that should be used for an equijoin. Use the USING clause to match only one column when more than one column matches. Table name or alias is not used in the referenced columns.
ANKUR RAINA
09-IT-4505
ANKUR RAINA
09-IT-4505
INSERT Statement:
Syntax:
UPDATE Statement:
UPDATE statement is used to modify the existing rows in a table. More than one row can be updated at a time (if required).
ANKUR RAINA
09-IT-4505
DELETE Statement:
DELETE Statement is used to remove existing rows from a table.
If one omits the WHERE clause, all the rows from the table will be deleted.
TRUNCATE Statement:
The TRUNCATE Statement removes all rows from a table, leaving the table empty and the table structure intact. It is a Data Definition Language (DDL) statement rather than a DML statement; cannot easily be undone.
ANKUR RAINA
09-IT-4505
ANKUR RAINA
09-IT-4505
CREATE Statement:
ANKUR RAINA
09-IT-4505
Dropping a Table:
All data and structure in the table are deleted. Any pending transactions are committed. All indexes are dropped. All constraints are dropped. You cannot roll back the DROP TABLE statement.
ANKUR RAINA
09-IT-4505
ANKUR RAINA
09-IT-4505
You cannot modify data in a view if it contains: Group functions A GROUP BY clause The DISTINCT keyword The pseudo column ROWNUM keyword Columns defined by expressions
You cannot add data in a view if following conditions along with conditions above prevail: NOT NULL columns in the base tables that are not selected by the view.
Sequences:
A sequence Can automatically generate unique numbers Is a sharable object Can be used to create a primary key value Replaces application code Speeds up the efficiency of accessing sequence values when cached in memory
Indexes:
An index: Is a schema object Can be used by the Oracle server to speed up the retrieval of rows by using a pointer Can reduce disk I/O by using a path access method to locate data quickly Is independent of the table that it indexes Is used and maintained automatically by the Oracle server
09-IT-4505
ANKUR RAINA
Indexes are created in the following two ways: Automatically: A unique index is created automatically when you define a PRIMARY KEY or UNIQUE constraint in a table definition. Manually: Users can create non-unique indexes on columns to speed up access to the rows.
Syntax:
Synonyms:
Simplify access to objects by creating a synonym (another name for an object). With synonyms, we can: Create an easier reference to a table that is owned by another user Shorten lengthy object names
ANKUR RAINA
09-IT-4505
REFERENCES
Web Resources
Books: Study material by Oracle University Press Modern Database Management by Jeffrey A. Hoffer, Mary B. Prescott and Fred R. McFadden
ANKUR RAINA
09-IT-4505