Upload
neelamgidda
View
216
Download
0
Embed Size (px)
Citation preview
8/8/2019 Oracle Seminar Final
1/18
ORACLE
8/8/2019 Oracle Seminar Final
2/18
Capabilities of SQL SELECT
StatementsSelectionProjection
Table 1 Table 2
Table 1Table 1
Join
8/8/2019 Oracle Seminar Final
3/18
Selecting All Columns
SELECT *
FROM departments;
8/8/2019 Oracle Seminar Final
4/18
Selecting Specific Columns
SELECT department_id, location_id
FROM departments;
8/8/2019 Oracle Seminar Final
5/18
Alternative Quote (q) Operator
Specify your own quotation mark delimiter.
Choose any delimiter.
Increase readability and usability.
SELECT department_name ||
q'[, it's assigned Manager Id: ]'
|| manager_id
AS "Department and Manager"
FROM departments;
8/8/2019 Oracle Seminar Final
6/18
Using the DESCRIBE Command
DESCRIBE employees
8/8/2019 Oracle Seminar Final
7/18
Using the WHERE Clause
SELECT employee_id, last_name, job_id, department_id
FROM employees
WHERE department_id = 90 ;
8/8/2019 Oracle Seminar Final
8/18
NVL Function
Converts a null value to an actual value: Data types that can be used are date, character, and
number.
Data types must match: NVL(commission_pct,0) NVL(hire_date,'01-JAN-97')
NVL(job_id,'No Job Yet')
8/8/2019 Oracle Seminar Final
9/18
SELECT last_name, salary, NVL(commission_pct, 0),
(salary*12) + (salary*12*NVL(commission_pct, 0)) AN_SAL
FROM employees;
Using the NVL Function
1
2
1 2
8/8/2019 Oracle Seminar Final
10/18
What Are Group Functions?
Group functions operate on sets of rows to
give one result per group.EMPLOYEES
Maximum salary in
EMPLOYEES table
8/8/2019 Oracle Seminar Final
11/18
Obtaining Data from Multiple Tables
EMPLOYEES DEPARTMENTS
8/8/2019 Oracle Seminar Final
12/18
Using a Subquery
to Solve a Problem Who has a salary greater than Abels?
Which employees have salaries greater than
Abels salary?
Main query:
What is Abels salary?
Subquery:
8/8/2019 Oracle Seminar Final
13/18
SELECT last_name, salary
FROM employees
WHERE salary >
(SELECT salary
FROM employeesWHERE last_name = 'Abel');
Using a Subquery
11000
8/8/2019 Oracle Seminar Final
14/18
Creating a Table
by Using a Subquery Create a table and insert rows by combining theCREATE TABLE statement and the AS subqueryoption.
Match the number of specified columns to thenumber of subquery columns.
Define columns with column names and
default values.
CREATE TABLE table
[(column, column...)]AS subquery;
8/8/2019 Oracle Seminar Final
15/18
Implementation of Read Consistency
SELECT *
FROM userA.employees;
UPDATE employees
SET salary = 7000
WHERE last_name = 'Grant';
Data
blocks
Undo
segments
Changedand unchangeddata
Before change
(old data)
User A
User B
Read-
consistentimage
8/8/2019 Oracle Seminar Final
16/18
FLASHBACK TABLE Statement
DROP TABLE emp2;
DROP TABLE succeeded.
FLASHBACK TABLE emp2 TO BEFORE DROP;
FLASHBACK TABLE succeeded.
SELECT original_name, operation, droptimeFROM recyclebin;
8/8/2019 Oracle Seminar Final
17/18
MERGE Statement
Provides the ability to conditionally update or insertdata into a database table
Performs an UPDATE if the row exists, and anINSERT if it is a new row:
Avoids separate updates Increases performance and ease of use
Is useful in data warehousing applications
8/8/2019 Oracle Seminar Final
18/18
MERGE Statement Syntax
You can conditionally insert or update rows in a table by usingthe MERGE statement.
MERGE INTO table_name table_alias
USING (table|view|sub_query) alias
ON
(join condition)WHEN MATCHED THEN
UPDATE SET
col1 = col_val1,
col2 = col2_val
WHENNOT MATCHED THEN
INSERT (column_list)
VALUES (column_values);