7/27/2019 day1 session1
1/64
Entry Level Technology Program
Satyam Learning Center ORACLE
ORACLE
Introduction
7/27/2019 day1 session1
2/64
Entry Level Technology Program
Satyam Learning Center ORACLE
ORACLEOak Ridge Automated Computer
And Logical Engine
It is a DBMS, which manages a large amount of data ina 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.
7/27/2019 day1 session1
3/64
Entry Level Technology Program
Satyam Learning Center ORACLE
ORACLE
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.
ORACLE SERVER
Database
CLIENT
CLIENT
SQL commands
Result
7/27/2019 day1 session1
4/64
Entry Level Technology Program
Satyam Learning Center ORACLE
DATABASE ARCHITECTURE
LOWER LEVEL STRUCTURE PL
LL
VL
..
..
..
..
..
..
..
..
..
U1 U2
..
..
..
SHADOW
PAGE
T1 T2
7/27/2019 day1 session1
5/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Physical Level
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 iscreated.
7/27/2019 day1 session1
6/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Physical structure
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)
7/27/2019 day1 session1
7/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Physical Structure
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)
7/27/2019 day1 session1
8/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Logical Structure
Logical Structure is independent of Physical structure.
Each Oracle database contains the following components.
oTablespaces
oSegments
oExtents
oBlocks
7/27/2019 day1 session1
9/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Tablespace
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 isautomatically 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 bychanging it to on-line.By making a tablespace off-line,
DBA can take the backup.
7/27/2019 day1 session1
10/64
Entry Level Technology Program
Satyam Learning Center ORACLE
SEGMENTS
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 It is used to store data of tables
Index Segments used to store indexes
Rollback segments Here Undo information is stored
Temporary segments Oracle stores Temporary
tables
7/27/2019 day1 session1
11/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Extents
The storage space is allocated to segments is in the formof Extents.Each Tablespace contains 65536 data files
N number of such Table spaces creates a database.
An extent is made with in a data fileN Number of continuous db blocks make up an Extent
Table
Table Segment
Extents
Tablespace
7/27/2019 day1 session1
12/64
Entry Level Technology Program
Satyam Learning Center ORACLE
QUERY PROCESS
CLIENT
DBSERVER PROCESS
CLIENT
PROCESS
1
2
31 PARSING
2 EXECUTE
3 FETCH
7/27/2019 day1 session1
13/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Oracle Instance
.
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.
7/27/2019 day1 session1
14/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Features & Benefits
9i
ORACLE
INTERNET
Scalability
Reliability
Single Dev Model
Common Skill Sets
One Management
Interface
7/27/2019 day1 session1
15/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Features
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
One Management interface for all applications
7/27/2019 day1 session1
16/64
Entry Level Technology Program
Satyam Learning Center ORACLE
9i Products
9i
IAS
9i
DATABASE
There are two products. They provide a complete and
simple infrastructure for internet applications.
7/27/2019 day1 session1
17/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Application Server
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
7/27/2019 day1 session1
18/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Oracle9i : OORDBMS
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 is1000 tera bytes)
7/27/2019 day1 session1
19/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Environment
Oracle uses two types of Environments for executing ourSQL statements. SQL*plus and iSQL*plus.
iSQL*plus is
oAn EnvironmentoOracle proprietary
oKeywords can be abbreviated
oRuns on a browser
oCentrally loaded, does not have to be implemented on
each machine
7/27/2019 day1 session1
20/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Tools of Oracle
SQL * PLUS
ISQLPLUS PL/SQL
FORMS
REPORTS
7/27/2019 day1 session1
21/64
Entry Level Technology Program
Satyam Learning Center ORACLE
SQL commands
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
7/27/2019 day1 session1
22/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Data Types
Data Type DescriptionVARCHAR2(size) Variable-length character data(4000bytes)
CHAR (size) Fixed-length character data up to 2000chars
NUMBER (p,s) Variable-length numeric data
DATE Date and time values
LONG Variable-length character data upto 2
GB
CLOB Character data up to 4 GB
RAW and LONG RAW Raw binary data (Raw is 2000 bytesand Long Raw is 4 GB)
7/27/2019 day1 session1
23/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Data Types
BLOB Binary data up to 4 GB
BFILE Binary data stored in anexternal file up to 4GB
NVARCHAR2(size) Variable-length characterdata(4000 bytes/chars)depending upon NationalCharacter Set
TIMESTAMP (precision) Date plus time
7/27/2019 day1 session1
24/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Writing BasicSQL SELECT Statements
7/27/2019 day1 session1
25/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Basic SELECT Statement
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table;
SELECT identifies what
columns
FROM identifies which
table
7/27/2019 day1 session1
26/64
Entry Level Technology Program
Satyam Learning Center ORACLE
SELECT *FROM DEPT;
Selecting All Tables and Columns
SELECT *FROM TAB;
DESC[RIBE] DEPT
SELECT DEPTNO,LOC
FROM DEPT;
7/27/2019 day1 session1
27/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Writing SQL Statements
SQL statements are not case sensitive.
SQL statements can be on one or more lines.
Keywords cannot be abbreviated or splitacross lines.
Clauses are usually placed on separate lines.
Indents are used to enhance readability.
7/27/2019 day1 session1
28/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Using Arithmetic Operators
SELECT ENAME, SAL, SAL + 300
FROM EMP;
7/27/2019 day1 session1
29/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Defining a Null Value
nullis a value that is unavailable, unassigned, unknown, orinapplicable.
A null is not the same as zero or a blank space.
SELECT ENAME, JOB, SAL, COMM
FROM EMP;
Null Values
7/27/2019 day1 session1
30/64
Entry Level Technology Program
Satyam Learning Center ORACLE
SELECT ENAME, 12*SAL*COMMFROM EMP;
Null Valuesin Arithmetic Expressions
Arithmetic expressions containing a null valueevaluate to null.
7/27/2019 day1 session1
31/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Defining a Column Alias
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 containsspaces or special characters or is case sensitive
7/27/2019 day1 session1
32/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Using Column Aliases
SELECTEENAME "Name", SAL*12 "Annual Salary"
FROM EMP;
SELECT ENAME AS name , COMM commission
FROM EMP;
7/27/2019 day1 session1
33/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Concatenation Operator
A concatenation operator:
Concatenates columns or character strings toother columns
Is represented by two vertical bars (||)
Creates a resultant column that is a character
expression
7/27/2019 day1 session1
34/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Using the ConcatenationOperator
SELECT ENAME || JOB AS "Employees"
FROM EMP;
7/27/2019 day1 session1
35/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Literal Character Strings
A literal is a character, a number, or a dateincluded in the SELECT list.
Date and character literal values must beenclosed within single quotation marks.
Each character string is output once for eachrow returned.
7/27/2019 day1 session1
36/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Using Literal CharacterStrings
SELECT ENAME ||' is a ' ||JOBAS "Employee Details"
FROM EMP;
7/27/2019 day1 session1
37/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Duplicate Rows
The default display of queries is all rows, includingduplicate rows.
SELECT DEPTNO
FROM EMP;
7/27/2019 day1 session1
38/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Eliminating Duplicate Rows
Eliminate duplicate rows by using the DISTINCT keywordin the SELECT clause.
SELECT DISTINCT DEPTNO
FROM EMP;
7/27/2019 day1 session1
39/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Restricting and Sorting Data
7/27/2019 day1 session1
40/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Objectives
After completing this lesson, you should be able todo the following:
Limit the rows retrieved by a query
Sort the rows retrieved by a query
7/27/2019 day1 session1
41/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Limiting the Rows Selected
Restrict the rows returned by using the WHERE clause.
The WHERE clause follows the FROM clause.
SELECT *|{[DISTINCT] column|expression [alias],...}FROM table
[WHERE condition(s)];
U i h Cl
7/27/2019 day1 session1
42/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Using theWHERE Clause
SELECT EMPNO, ENAME, JOB, DEPTNO
FROM EMP
WHERE DEPTNO = 30 ;
7/27/2019 day1 session1
43/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Character Strings and Dates
Character strings and date values are enclosed in singlequotation marks.
Character values are case sensitive, and date values areformat sensitive.
The default date format is DD-MON-RR.
SELECT ENAME, JOB, DEPTNO
FROM EMP
WHERE ENAME = 'WARD';
7/27/2019 day1 session1
44/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Comparison Conditions
Operator
=
>
>=
=10000
AND JOB LIKE '%MAN%';
Using the OR Operator
7/27/2019 day1 session1
54/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Using the OROperator
OR requires either condition to be true.
SELECT EMPNO, ENAME, JOB, SAL
FROM EMP
WHERE SAL >= 10000
OR JOB LIKE '%MAN%';
Using the NOT Operator
7/27/2019 day1 session1
55/64
Entry Level Technology Program
Satyam Learning Center ORACLE
SELECT ENAME, JOB
FROM EMP
WHERE JOB
NOT IN (MANAGER', 'CLERK', 'SALESMAN');
Using theNOT Operator
Rules of Precedence
7/27/2019 day1 session1
56/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Rules of Precedence
Override rules of precedence by using parentheses.
Order Evaluated Operator
1 Arithmetic operators
2 Concatenation operator
3 Comparison conditions4 IS[NOT]NULL, LIKE, [NOT]IN
5 [NOT] BETWEEN
6 NOT logical condition
7AND
logical condition
8 ORlogical condition
Rules of Precedence
7/27/2019 day1 session1
57/64
Entry Level Technology Program
Satyam Learning Center ORACLE
SELECT ENAME, JOB, SAL
FROM EMP
WHERE JOB = 'SALESMAN'
OR JOB = 'PRESIDENT'
AND SAL > 15000;
Rules of Precedence
Rules of Precedence
7/27/2019 day1 session1
58/64
Entry Level Technology Program
Satyam Learning Center ORACLE
SELECT ENAME, JOB, SAL
FROM EMP
WHERE (JOB = 'SALESMAN'
OR JOB = 'PRESIDENT')
AND SAL > 15000;
Rules of Precedence
Use parentheses to force priority.
Cl
7/27/2019 day1 session1
59/64
Entry Level Technology Program
Satyam Learning Center ORACLE
SELECT ENAME, JOB, DEPTNO, HIREDATE
FROM EMP
ORDER BY HIREDATE ;
ORDER BY Clause
Sort rows with the ORDER BY clause
ASC: ascending order, default
DESC: descending order
The ORDER BY clause comes last in the SELECT statement.
Sorting in Descending Order
7/27/2019 day1 session1
60/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Sorting in Descending Order
SELECT ENAME, JOB, DEPTNO, HIREDATE
FROM EMP
ORDER BY HIREDATE DESC ;
Sorting by Column Alias
7/27/2019 day1 session1
61/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Sorting by Column Alias
SELECT EMPNO, ENAME, SAL*12 annsal
FROM EMP
ORDER BY annsal;
Sorting by Multiple Columns
7/27/2019 day1 session1
62/64
Entry Level Technology Program
Satyam Learning Center ORACLE
The order ofORDER BY list is the order of sort.
You can sort by a column that is not in theSELECT list.
SELECT EMPNO, DEPTNO, SAL
FROM EMP
ORDER BY DEPTNO, SAL DESC;
Summary
7/27/2019 day1 session1
63/64
Entry Level Technology Program
Satyam Learning Center ORACLE
Summary
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table
[WHERE condition(s)][ORDER BY {column, expr, alias} [ASC|DESC]];
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
Exercise
7/27/2019 day1 session1
64/64
Entry Level Technology Program
Exercise
1) Display the names with single word 2) Display the names with two words 3) Display the names with exactly three words 4) Display all the salaries beginning with digit 2 5) Display all the names with second letter as A
6) Display the employees who joined between any two givendates
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.