Vous êtes sur la page 1sur 64

Entry Level Technology Program

ORACLE
Introduction

Satyam Learning Center

ORACLE

Entry Level Technology Program

ORACLE Oak Ridge Automated Computer And Logical Engine

It is a DBMS, which manages a large amount of data in a multi user environment so that many users concurrently access the data. It Also provides security and Recovery. It stores and manages data using relational model. Oracle is the name of database management system developed by Oracle corporation.

Satyam Learning Center

ORACLE

ORACLE
Entry Level Technology Program

Oracle server manages data in the database. Users access Oracle server using SQL commands. So Oracle server receives SQL commands from users and execute them on the database. SQL commands
CLIENT Result Database CLIENT
Satyam Learning Center ORACLE

ORACLE SERVER

DATABASE ARCHITECTURE
Entry Level Technology Program

U1

U2

VL
SHADOW PAGE .. .. ..

.. .. .. T1

.. .. ..

.. .. ..

LL

T2

LOWER LEVEL STRUCTURE

PL

Satyam Learning Center

ORACLE

Physical Level
Entry Level Technology Program

The Physical structure of the database is placed in Physical level. It is physically a set of operating system files. There are 3 types. Data Files

Redo log files


Control files These files automatically creates when database is created.

Satyam Learning Center

ORACLE

Physical structure
Entry Level Technology Program

Data Files It contains the data of the database. Every table that is stored in the database is a part of these files. Only Oracle Server can interpret these data files.
Redo Log Files Every database has a set of two or more Redo Log files. The set of redo log files is known as databases redo log. Redo Log files are used in failure recovery.

All changes made to the database are written to redo log file.. ( filenames redo01.log)

Satyam Learning Center

ORACLE

Physical Structure
Entry Level Technology Program

Control Files Every Oracle database has a control file. It contains vital data regarding the database. It contains ( Extension of file is ctl)
Database Name

Names and locations of data files and redo log files.

Path Oracle\oradata\orcl ( to see all the 3 types of files)

Satyam Learning Center

ORACLE

Logical Structure
Entry Level Technology Program

Logical Structure is independent of Physical structure. Each Oracle database contains the following components. oTablespaces oSegments

oExtents
oBlocks

Satyam Learning Center

ORACLE

Tablespace
Entry Level Technology Program

Each Database is a collection of tablespaces.For example we can use a table space called PAYROLL to store all the data related to payroll application. Every database contains SYSTEM tablespace. This is automatically created when a database is created. SYSTEM tablespace contains the data dictionary tables. It is possible to make tablespace temporarily unavailable by making it off-line and make it available again by changing it to on-line.By making a tablespace off-line, DBA can take the backup.

Satyam Learning Center

ORACLE

SEGMENTS
Entry Level Technology Program

Data into tablespaces comes in the form of segments. Example Table is a segment An Oracle database requires upto 4 types of segments Data segments Index Segments It is used to store data of tables used to store indexes

Rollback segments Here Undo information is stored

Temporary segments Oracle stores Temporary tables

Satyam Learning Center

ORACLE

Extents
Entry Level Technology Program

The storage space is allocated to segments is in the form of Extents.Each Tablespace contains 65536 data files N number of such Table spaces creates a database. An extent is made with in a data file N Number of continuous db blocks make up an Extent Table Table Segment Table space

Satyam Learning Center

ORACLE

Extents

QUERY PROCESS
Entry Level Technology Program

1 2 3

PARSING EXECUTE FETCH

3 2
SERVER PROCESS

DB

CLIENT PROCESS

CLIENT

Satyam Learning Center

ORACLE

Oracle Instance
Entry Level Technology Program

. Every oracle database is associated with an Oracle Instance. Every time a database is started, a memory area called System Global Area(SGA) or Shared Global Area is allocated and one or more processes are started.

The combination of SGA and Oracle processes is called as Oracle Instance.

Satyam Learning Center

ORACLE

Features & Benefits


Entry Level Technology Program

ORACLE
Scalability One Management Interface

9i
INTERNET

Reliability
Single Dev Model
Satyam Learning Center ORACLE

Common Skill Sets

Features
Entry Level Technology Program

Oracle Offers a comprehensive high performance infrastructure for e-business.It is called Oracle9i.It provides every thing needed to develop, deploy and manage Internet Applications. Benefits Scalability from departments to enterprise e-business sites Reliable, available and secure architecture

One development model, easy development options


Common skill sets including SQL, PL/SQL,JAVA and XML
Satyam Learning Center ORACLE for all applications One Management interface

9i Products
Entry Level Technology Program

There are two products. They provide a complete and simple infrastructure for internet applications.

IAS

DATABASE

9i
Satyam Learning Center ORACLE

9i

Application Server
Entry Level Technology Program

9i Application server runs all the applications and 9i database stores our data. Oracle 9i Application server runs Portals or web sites

Java Transactional Applications


Provides integration between users, applications and data

Satyam Learning Center

ORACLE

Oracle9i : OORDBMS
Entry Level Technology Program

User-Defined data types and objects Fully compatible with relational database Support of multimedia and Large objects It also support client server and web based applications Oracle 9i can scale tens of thousands of concurrent users and support up to 512 petabytes of data ( A peta byte is 1000 tera bytes)

Satyam Learning Center

ORACLE

Environment
Entry Level Technology Program

Oracle uses two types of Environments for executing our SQL statements. SQL*plus and iSQL*plus. iSQL*plus is oAn Environment

oOracle proprietary
oKeywords can be abbreviated oRuns on a browser

oCentrally loaded, does not have to be implemented on each machine


Satyam Learning Center ORACLE

Tools of Oracle
Entry Level Technology Program

SQL * PLUS ISQLPLUS PL/SQL FORMS REPORTS

Satyam Learning Center

ORACLE

SQL commands
Entry Level Technology Program

Data Definition Language (DDL) : CREATE, ALTER, DROP, TRUNCATE Data Manipulation Language (DML) : INSERT, UPDATE, DELETE Transaction Control Language (TCL) : COMMIT, ROLLBACK, SAVEPOINT Data Retrieval Language (DRL) : SELECT Data Control Language (DCL) : GRANT, REVOKE

Satyam Learning Center

ORACLE

Data Types
Entry Level Technology Program

VARCHAR2(size) bytes) CHAR (size) chars NUMBER (p,s) DATE LONG GB CLOB

Data Type

Variable-length character data(4000 Fixed-length character data up to 2000 Variable-length numeric data Date and time values Variable-length character data upto 2 Character data up to 4 GB Raw binary data (Raw is 2000 bytes and Long Raw is 4 GB)
ORACLE

Description

RAW and LONG RAW


Satyam Learning Center

Data Types
Entry Level Technology Program

BLOB BFILE

Binary data up to 4 GB Binary data stored in an external file up to 4GB

NVARCHAR2(size)

Variable-length character data(4000 bytes/chars) depending upon National Character Set TIMESTAMP (precision) Date plus time

Satyam Learning Center

ORACLE

Entry Level Technology Program

Writing Basic SQL SELECT Statements

Satyam Learning Center

ORACLE

Basic SELECT Statement


Entry Level Technology Program

SELECT FROM

*|{[DISTINCT] column|expression [alias],...} table;

SELECT identifies what columns FROM identifies which table

Satyam Learning Center

ORACLE

Selecting All Tables and Columns


Entry Level Technology Program

SELECT * FROM TAB; SELECT * FROM DEPT;

DESC[RIBE] DEPT

SELECT DEPTNO,LOC FROM DEPT;

Satyam Learning Center

ORACLE

Writing SQL Statements


Entry Level Technology Program

SQL statements are not case sensitive. SQL statements can be on one or more lines. Keywords cannot be abbreviated or split across lines. Clauses are usually placed on separate lines. Indents are used to enhance readability.

Satyam Learning Center

ORACLE

Using Arithmetic Operators


Entry Level Technology Program

SELECT ENAME, SAL, SAL + 300 FROM EMP;

Satyam Learning Center

ORACLE

Defining a Null Value


Entry Level Technology Program

null is a value that is unavailable, unassigned, unknown, or inapplicable. A null is not the same as zero or a blank space.

SELECT ENAME, JOB, SAL, COMM FROM EMP;

Satyam Learning Center

ORACLE

Null Values in Arithmetic Expressions


Entry Level Technology Program

Arithmetic expressions containing a null value evaluate to null.

SELECT ENAME, 12*SAL*COMM FROM EMP;

Satyam Learning Center

ORACLE

Defining a Column Alias


Entry Level Technology Program

A column alias: Renames a column heading Is useful with calculations Immediately follows the column name - there can also be the optional AS keyword between the column name and alias Requires double quotation marks if it contains spaces or special characters or is case sensitive

Satyam Learning Center

ORACLE

Using Column Aliases


Entry Level Technology Program

SELECT ENAME AS name , COMM commission FROM EMP;

SELECT EENAME "Name", SAL*12 "Annual Salary" FROM EMP;

Satyam Learning Center

ORACLE

Concatenation Operator
Entry Level Technology Program

A concatenation operator: Concatenates columns or character strings to other columns Is represented by two vertical bars (||) Creates a resultant column that is a character expression

Satyam Learning Center

ORACLE

Entry Level Technology Program

Using the Concatenation Operator

SELECT FROM

ENAME || JOB AS "Employees" EMP;

Satyam Learning Center

ORACLE

Literal Character Strings


Entry Level Technology Program

A literal is a character, a number, or a date included in the SELECT list. Date and character literal values must be enclosed within single quotation marks. Each character string is output once for each row returned.

Satyam Learning Center

ORACLE

Entry Level Technology Program

Using Literal Character Strings

SELECT ENAME ||' is a ' ||JOB AS "Employee Details" FROM EMP;

Satyam Learning Center

ORACLE

Duplicate Rows
Entry Level Technology Program

The default display of queries is all rows, including duplicate rows.

SELECT DEPTNO FROM EMP;

Satyam Learning Center

ORACLE

Eliminating Duplicate Rows


Entry Level Technology Program

Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause.

SELECT DISTINCT DEPTNO FROM EMP;

Satyam Learning Center

ORACLE

Entry Level Technology Program

Restricting and Sorting Data

Satyam Learning Center

ORACLE

Objectives
Entry Level Technology Program

After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query Sort the rows retrieved by a query

Satyam Learning Center

ORACLE

Limiting the Rows Selected


Entry Level Technology Program

Restrict the rows returned by using the WHERE clause.


SELECT FROM [WHERE *|{[DISTINCT] column|expression [alias],...} table condition(s)];

The WHERE clause follows the FROM clause.

Satyam Learning Center

ORACLE

Using the WHERE Clause


Entry Level Technology Program

SELECT EMPNO, ENAME, JOB, DEPTNO FROM EMP

WHERE DEPTNO = 30 ;

Satyam Learning Center

ORACLE

Character Strings and Dates


Entry Level Technology Program

Character strings and date values are enclosed in single quotation marks. Character values are case sensitive, and date values are format sensitive. The default date format is DD-MON-RR.

SELECT ENAME, JOB, DEPTNO


FROM WHERE EMP ENAME = 'WARD';

Satyam Learning Center

ORACLE

Comparison Conditions
Entry Level Technology Program

Operator = > >= < <= <>

Meaning Equal to Greater than Greater than or equal to Less than Less than or equal to Not equal to

Satyam Learning Center

ORACLE

Using Comparison Conditions


Entry Level Technology Program

SELECT ENAME, SAL FROM WHERE EMP SAL <= 3000;

Satyam Learning Center

ORACLE

Entry Level Technology Program

Other Comparison Conditions

Operator BETWEEN ...AND...

Meaning Between two values (inclusive),

IN(set)
LIKE IS NULL

Match any of a list of values


Match a character pattern Is a null value

Satyam Learning Center

ORACLE

Using the BETWEEN Condition


Entry Level Technology Program

Use the BETWEEN condition to display rows based on a range of values.

SELECT ENAME, SAL FROM WHERE EMP SAL BETWEEN 2500 AND 3500;

Lower limit Upper limit

Satyam Learning Center

ORACLE

Using the IN Condition


Entry Level Technology Program

Use the IN membership condition to test for values in a list.

SELECT EMPNO, ENAME, SAL, FROM WHERE EMP

MGR

MGR IN (7900, 7566,7982 );

Satyam Learning Center

ORACLE

Using the LIKE Condition


Entry Level Technology Program

Use the LIKE condition to perform wildcard searches of valid search string values. Search conditions can contain either literal characters or numbers:

% denotes zero or many characters. _ denotes one character.

SELECT FROM WHERE

ENAME EMP ENAME LIKE 'S%';

Satyam Learning Center

ORACLE

Using the LIKE Condition


Entry Level Technology Program

You can combine pattern-matching characters.

SELECT ENAME FROM WHERE EMP ENAME LIKE '_o%';

You can use the ESCAPE identifier to search for the actual % and _ symbols.

Satyam Learning Center

ORACLE

Using the NULL Conditions


Entry Level Technology Program

Test for nulls with the IS NULL operator.


SELECT ENAME, MGR

FROM
WHERE

EMP
MGR IS NULL;

Satyam Learning Center

ORACLE

Logical Conditions
Entry Level Technology Program

Operator AND OR

Meaning Returns TRUE if both component conditions are true Returns TRUE if either component condition is true Returns TRUE if the following condition is false

NOT

Satyam Learning Center

ORACLE

Using the AND Operator


Entry Level Technology Program

AND requires both conditions to be true.


SELECT EMPNO, ENAME, JOB, SAL

FROM
WHERE AND

EMP
SAL >=10000 JOB LIKE '%MAN%';

Satyam Learning Center

ORACLE

Using the OR Operator


Entry Level Technology Program

OR requires either condition to be true.

SELECT EMPNO, ENAME, JOB, SAL FROM EMP

WHERE
OR

SAL >= 10000


JOB LIKE '%MAN%';

Satyam Learning Center

ORACLE

Using the NOT Operator


Entry Level Technology Program

SELECT ENAME, JOB

FROM

EMP

WHERE

JOB

NOT IN (MANAGER', 'CLERK', 'SALESMAN');

Satyam Learning Center

ORACLE

Rules of Precedence
Entry Level Technology Program

Order Evaluated 1 2 3 4 5 6 7 8

Operator Arithmetic operators Concatenation operator Comparison conditions IS [NOT] NULL, LIKE, [NOT] IN [NOT] BETWEEN NOT logical condition AND logical condition OR logical condition

Override rules of precedence by using parentheses.

Satyam Learning Center

ORACLE

Rules of Precedence
Entry Level Technology Program

SELECT ENAME, JOB, SAL FROM WHERE OR EMP JOB = 'SALESMAN' JOB = 'PRESIDENT'

AND

SAL > 15000;

Satyam Learning Center

ORACLE

Rules of Precedence
Entry Level Technology Program

Use parentheses to force priority.


SELECT ENAME, JOB, SAL FROM WHERE OR AND EMP (JOB = 'SALESMAN' JOB = 'PRESIDENT') SAL > 15000;

Satyam Learning Center

ORACLE

ORDER BY Clause
Entry Level Technology Program

Sort rows with the ORDER BY clause

ASC: ascending order, default DESC: descending order


The ORDER BY clause comes last in the SELECT statement.

SELECT FROM

ENAME, JOB, DEPTNO, HIREDATE EMP

ORDER BY HIREDATE ;

Satyam Learning Center

ORACLE

Sorting in Descending Order


Entry Level Technology Program

SELECT

ENAME, JOB, DEPTNO, HIREDATE

FROM

EMP

ORDER BY HIREDATE DESC ;

Satyam Learning Center

ORACLE

Sorting by Column Alias


Entry Level Technology Program

SELECT EMPNO, ENAME, SAL*12 annsal FROM EMP

ORDER BY annsal;

Satyam Learning Center

ORACLE

Sorting by Multiple Columns


Entry Level Technology Program

The order of ORDER BY list is the order of sort.


SELECT EMPNO, DEPTNO, SAL

FROM

EMP

ORDER BY DEPTNO, SAL DESC;

You can sort by a column that is not in the SELECT list.

Satyam Learning Center

ORACLE

Summary
Entry Level Technology Program

In this lesson, you should have learned how to:

Use the WHERE clause to restrict rows of output


Use the comparison conditions Use the BETWEEN, IN, LIKE, and NULL conditions Apply the logical AND, OR, and NOT operators

Use the ORDER BY clause to sort rows of output


SELECT FROM [WHERE [ORDER BY *|{[DISTINCT] column|expression [alias],...} table condition(s)] {column, expr, alias} [ASC|DESC]];

Satyam Learning Center

ORACLE

Exercise
Entry Level Technology Program

1) 2) 3) 4) 5) 6)

Display the names with single word Display the names with two words Display the names with exactly three words Display all the salaries beginning with digit 2 Display all the names with second letter as A Display the employees who joined between any two given dates 7) Display the names and experience of all the employees 8) How many employees does not draw salary between 5000 and 10000 9) Display all the names whose names contain underscore(_) 10)Calculate the experience in years for each employee and display along with their names, in descending order.

Satyam Learning Center

ORACLE

Vous aimerez peut-être aussi