0% found this document useful (0 votes)
35 views59 pages

New Microsoft Office Power Point Presentation

This document provides an introduction to Structured Query Language (SQL) and the Oracle 9i database. It covers the following key points: 1) It describes the features and benefits of Oracle 9i, including its scalability, reliability, security, and support for standard technologies and data types. Oracle 9i consists of the Oracle 9i Application Server and Oracle 9i Database. 2) It provides an overview of relational database concepts, including the relational model proposed by Dr. E.F. Codd and definitions of key terms like relations, attributes, and primary keys. 3) It explains how to communicate with an RDBMS using SQL and describes common SQL statements for data retrieval, manipulation

Uploaded by

alogarg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views59 pages

New Microsoft Office Power Point Presentation

This document provides an introduction to Structured Query Language (SQL) and the Oracle 9i database. It covers the following key points: 1) It describes the features and benefits of Oracle 9i, including its scalability, reliability, security, and support for standard technologies and data types. Oracle 9i consists of the Oracle 9i Application Server and Oracle 9i Database. 2) It provides an overview of relational database concepts, including the relational model proposed by Dr. E.F. Codd and definitions of key terms like relations, attributes, and primary keys. 3) It explains how to communicate with an RDBMS using SQL and describes common SQL statements for data retrieval, manipulation

Uploaded by

alogarg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 59

Structured Query

Language (SQL)
TechnoLedge Services
Alok Garg
Chapter 1
Introduction
Introduction
Objectives:-

After Completing this lesson, you should be able to do


the following:-
 List the features of Oracle9i
 Discuss the theoretical and physical aspects of a relational

database
 Describe the Oracle implementation of the RDBMS and

ORDBMS
Oracle9i Features
Oracle9i offers a comprehensive high-performance
infrastructure for e-business. It is called Oracle9i and includes
everything needed to develop,deploy and manage internet
applications.
Benefits include:-
Scalability from departments to enterprise e-business sites.
Robust,reliable,available,secure architecture.
One development model,easy deployment options
Leverage an organization’s current skillset throughout the Oracle
Platform(including SQL,PL/SQL,Java and XML)
One Management Interface for all applications.
Industry standard technologies,no proprietary lock-in.
Oracl9i
It has two products that provide a complete and
simple infrastructure for Internet applications :-
Oracle9i Application Server
Oracle9i Database
Oracle9i Application Server
Oracle9i Application Server runs all your applications.
Oracle9i Database stores all your data.
Oracle9i Application Server is the only application
server to include services for all the different server
applications you may want to run such as :-
Portals or Web sites
Java Transactional applications
Business Intelligence applications
It also provides integration between users,
applications and data throughout your organization.
Oracle9i Database
The roles of the two products are very straightforward. Oracle9i
manages all your data. This is not just the object relational data that
you expect an enterprise database to manage. It can also be
unstructured data like:-
Spreadsheets
Word Documents
PowerPoint presentations
XML
Multimedia data types like MP3,graphics,videos and more
Data does not even have to be in database. 9i DB has services thru
which you can store metadata about info stored in file systems. You
can use database server to manage and serve information wherever
located.
Relational Database Concept
Dr. E.F. Codd proposed the relational model for
database systems in 1970.
It is the basis for the relational database management
system ( RDBMS).
The relational model consists of the following:-
Collections of objects or relations.
Set of operations to act on the relations.
Data integrity for accuracy and consistency.
Definition of a relational Database
A relational database is a collection of relations or
two-dimensional tables.
A relational database uses relations or two-
dimensional tables to store information.
For example – You might want to store information
about all the employees in your company. In a
relational database, you create several tables to store
different pieces of information about your employees
such as an employee table, a department table and a
salary table
Data Models
Models are a cornerstone of design. Engineers build a model of a car to work out any
details before putting it into production. In the same manner, system designers develop
models to explore ideas and improve the understanding of the database design.
Purpose of Models :-
Models help communicate the concept in people’s minds. They can be used to do the
following :-
 Communicate
 Categorize

 Describe

 Specify

 Investigate
 Evolve

 Analyze

 Imitate

The objective is to produce a model that fits a multitude of these uses, can be
understood by an end user, and contains sufficient detail for a developer to build a
database system.
Database Terminology
ER Modelling
Entities
Attributes
RelationShips
Unique Identifiers
Relating Multiple Tables
Guidelines for Primary Keys & Foreign Keys
Relational Database Terminology
Table
Row
Column
Primary Key / Foreign Key
Field
Relational Database Properties
It can be accessed and modified by executing SQL
statements.
Contains a collection of tables with no physical
pointers.
Uses a set of operators
Communicating with RDBMS using SQL
SQL has following advantages:-
Efficient
Easy to learn and Use
Functionally Complete [ You can define, retrieve and
manipulate data in the tables ]
SQL Statements
Data Retrieval
SELECT
Data Manipulation
INSERT
UPDATE
DELETE
MERGE
DATA DEFINITION LANGUAGE
CREATE
ALTER
DROP
RENAME
TRUNCATE
SQL Statemens
Transaction Control
COMMIT
ROLLBACK
SAVEPOINT
Data Control
GRANT
REVOKE
Chapter 2
Writing Basic
SQL SELECT Statements
Objectives
To provide ability to do the following:-

List the capabilities of SQL SELECT statements


Execute a basic SELECT statement
Capabilities of SQL SELECT Statement
A SELECT Statement retrieves information from a
database. You can do the following using it :-
Projection :-
 Let your query return you specific columns in a table that you
want. Choose a select few columns or all columns from the table
Selection :-
 Let your query return you specific rows in a table that you want.
You can use various criteria to restrict rows that you want.
Joining :-
 Use Join to bring together data stored in different tables by
creating links between them.
Basic SELECT Statement
SELECT * | { [DISTINCT] column | expression [alias] ,
…….. }
FROM table ;

SELECT - identifies what columns.


FROM - identifies what tables.
Basic SELECT Statements
Syntax :-
SELECT - List of one or more columns
* - Select all columns
DISTINCT - suppresses duplicates
Column|expression - selects the named column
or the expression.
Alias - Gives selected columns different
headings.
FROM table - Specifies the table containing the
columns
Basic SELECT Statements
We would use following terms for
Keyword :- Individual SQL element

Clause :- Part of a SQL statement.

Statement :- Combination of two or more clauses


Selecting ALL Columns
First Approach
Select *
From Departments
Second Approach
Select department_id,department_name,manager_id
From Departments
Selecting Specific columns
Writing SQL Statements
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
Executing SQL Statements
Using iSQLPLus,
click the Execute button to run the command or
commands in the Editing Window.
Column Heading Defaults
Arithmetic Expressions
Create Expressions with number and date data by
using arithmetic operators.
Operator Description
+ Add
- Subtract
* Multiply
/ Divide
Using Arithmetic Operators
Example:-
Select last_name,salary,salary+300
From Employee;

Operator Precedence:-
*
/
+
-
Operator Precedence
Using Parentheses
To avoid operator precedence rules, use parentheses
Defining a NULL Value
A NULL is a value that is unavailable, unassigned,
unknown or inapplicable.
A NULL is not same as zero or blank space.
Arithmetic expressions containing a null value
evaluate to NULL.
Defining a Column Alias
A column alias:
Renames a column heading
Is useful with Calculations.
Immediately follows the column name – there can also
be an optional AS keyword between column name and
alias.
Requires double quotation marks if it contains spaces or
special characters or is case sensitive.
Concatenation Operator
A concatenation operator :-
Concatenation columns or character strings to other
columns.
Is represented by two vertical bars
Creates a resultant column that is a character
expression.
Example :-
SELECT last_name||job_id AS “Employees”
FROM employees;
Literal Character Strings
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.

SELECT last_name || ‘ is a ‘ ||job_id


FROM employees;
Duplicate Rows
Duplicate Rows :-
The default display of queries is all rows, including
duplicate rows.
 SELECT department_id
 FROM employees

Eliminating Duplicate Rows :-


Eliminate Duplicate rows by using the DISTINCT
keyword in the SELECT clause.
Displaying Table Structure
DESC tablename
DESCRIBE tablename
Restricting and Sorting Data
Learn how to :-
Limits the rows restricted by a query
Sort the rows restricted by a query
Limiting Rows using a Selection
While restricting data from the database, you may
need to restrict the rows of data that are displayed or
specify the order in which the rows are displayed.
For eg; You may want to display all the employees in
department 90 only.
This method of restriction is the basis of WHERE clause
in SQL.
Limiting the Rows Selected
Restrict the rows returned by using the WHERE clause.
SELECT * | { [DISTINCT] column | expression [alias ] , ……. }
FROM table
[ WHERE condition(s) ]

WHERE – Restricts the query to rows that meet a condition.


Condition - Is composed of column names , expressions ,
constants , and a comparison operator.
Limiting the Rows Selected
WHERE clause can compare values in columns, literal
values, arithmetic expressions , or functions.

It consists of three elements:-


Column name
Comparison condition
Column name, constant or list of Values
Using the WHERE Clause
SELECT employee_id , last_name , job_id
FROM employees
WHERE department_id = 90
Character Strings and Dates
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 last_name,job_id,department_id
FROM employees
WHERE last_name = ‘Whalen’;
Comparison Conditions
Operators
=
>
>=
<
<=
<>
Other Comparison Conditions
Operator
BETWEEN ….. AND ……
IN(Set)
LIKE
IS NULL
Using the BETWEEN Condition
Use the BETWEEN Condition to display rows based
on a range of values.

SELECT last_name,salary
FROM employees
WHERE salary BETWEEN 2500 and 3000;
Using the IN Condition
Use the IN membership condition to test the values in
a list.

SELECT employee_id,last_name,salary
FROM employees
WHERE manager_id IN(1001,1002,1003);
Using the LIKE Condition
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 characters
Example
SELECT first_name
FROM employees
WHERE first_name LIKE ‘S%’;
Using the LIKE Condition
You can combine pattern-matching characters:-
SELECT last_name
FROM employees
WHERE last_name LIKE ‘_o%’;

The ESCAPE Option:-


SELECT employee_id
FROM employees
WHERE job_id LIKE ‘%SA\_%’ ESCAPE ‘\’;
Using the NULL Condition
Test for nulls with the IS NULL Operator :-
SELECT last_name , manager_id
FROM employees
WHERE manager_id IS NULL;
Logical Conditions
Operator:-
AND
OR
NOT

Example :-
SELECT emp_id,last_name,job_id,salary
FROM employees
WHERE salary>=10000
AND job_id LIKE ‘%MAN%’;
Rules of Precedence
Order Evaluated Operator
1 Arithmetic Operator
2 Concatenation Operator
3 Comparison Operator
4 IS NULL,LIKE,IN
5 BETWEEN
6 NOT logical condition
7 AND logical condition
8 OR logical condition

Override rules of precedence by using parentheses.


Example of Rules of Precedence
SELECT last_name,job_id,salary
FROM employees
WHERE job_id = ‘SA_REP’
OR job_id = ‘AD_PRES’
AND salary > 15000;
Rules of Precedence
Use Parentheses to force priority

SELECT last_name,job_id,salary
FROM employees
WHERE (job_id = ‘SA_PREP’
OR job_id = ‘AD_PRES’)
AND salary > 15000;
ORDER BY Clause
Sorting in Descending Order
Sorting by Column Alias
Sorting by Multiple Columns
Summary

You might also like