Oracle SQL - Session1
Oracle SQL - Session1
Session 1
Objectives
• Introduction to Databases
• DBMS
• RDBMS
• Oracle
• SQL
• Data type
• Types of SQL(DRL,DDL, DML, DCL, TL)
• Writing Select Statement.
Introduction to Database
Database:
• A collection of all operational data where data redundancy is
minimized, concurrency access is achieved and data
independence is achieved.
• Examples: Attendance Register, Telephone Directory.
Syntax:
SELECT
SELECT *|{[DISTINCT]
*|{[DISTINCT] column|expression
column|expression [alias],...}
[alias],...}
FROM
FROM table;
table;
Example:
Select * from emp; column
Select sal*12 from emp;
expression
Selecting All Columns
SELECT *
FROM departments;
Selecting Specific Columns
SELECT department_id, location_id
FROM departments;
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.
Arithmetic Expressions
Create expressions with number and date data by using
arithmetic operators.
Operator Description
+ Add
- Subtract
* Multiply
/ Divide
Using Arithmetic Operators
SELECT last_name, salary, salary + 300
FROM employees;
…
Operator Precedence
__
** // ++
…
Using Parentheses
SELECT last_name, salary, 12*(salary+100)
FROM employees;
…
Defining a Null Value
A null is a value that is unavailable, unassigned,
unknown, or inapplicable.
A null is not the same as zero or a blank space.
…
Null Values
in Arithmetic Expressions
Arithmetic expressions containing a null value evaluate to
null.
SELECT last_name, 12*salary*commission_pct
FROM employees;
…
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 contains spaces
or special characters or is case sensitive
Using Column Aliases
SELECT last_name AS name, commission_pct comm
FROM employees;
…
Concatenation Operator
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
Using the Concatenation Operator
…
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.
Using Literal Character Strings
…
Duplicate Rows
The default display of queries is all rows, including
duplicate rows.
SELECT
SELECT department_id
department_id
FROM
FROM employees;
employees;
…
Eliminating Duplicate Rows
Eliminate duplicate rows by using the DISTINCT
keyword in the SELECT clause.
SELECT DISTINCT department_id
FROM employees;
Limiting Rows Using a Selection
EMPLOYEES
“retrieve all
employees
in department 90”
Limiting the Rows Selected
Restrict
the rows returned by using the WHERE clause.
The WHERE clause follows the FROM clause.
= Equal to
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%';