Sunteți pe pagina 1din 4

Analytical SQL Examples

Purpose
This tutorial covers the analytical SQL features that are part of Oracle Database 12c.
The key benefits provided by Oracles in-database analytical functions and features are:
1. Enhanced Developer Productivity - enable developers to perform complex
analyses with much clearer and more concise SQL code. Complex tasks can now
be expressed using single SQL statement which is quicker to formulate and
maintain, resulting in greater productivity.
2. Improved Query Speed - processing optimizations supported by in-database
analytics enable significantly better query performance. Actions which before
required self-joins or complex procedural processing may now be performed in
native SQL.
3. Improved Manageability - ability to access a consolidated view of all data types
and sources is simplified when applications share a common relational
environment rather than a mix of calculation engines with incompatible data
structures.
4. Minimized Learning Effort - SQL analytic functions minimize the need to learn
new keywords because the syntax leverages existing well-understood keywords.
5. Industry standards based syntax - Oracle's features conform to ANSI SQL
standard and are supported by a large number of independent software vendors.

Time to Complete
Approximately 60 minutes.

Introduction

The in-database analytical functions features that are embedded inside the Oracle
Database can be used to answer a wide variety of business problems. Developers and
business users can access a wide range of analytic features and combine their results
with other SQL queries and analytical pipelines to gain deeper insights. Oracle's
Database includes the following features:

Ranking
Windowing
Reporting Aggregates
LAG/LEAD
FIRST/LAST
Inverse Percentile

Hypothetical Rank and Distribution

Pattern Matching

Modeling

Advanced aggregations

User defined functions

Hardware and Software Requirements

Requires Oracle Database 12c

Prerequisites

Have access to Oracle Database 12c with a sample sales history schema, the
SYS user with SYSDBA privilege and OS authentication (so that you can execute
the sqlplus / as sysdba command.)

Examples create additional tables and views within the SH user schema.

Have downloaded and the SQL scripts (which is in the Scripts subdirectory of this
tutorial) into a working directory.

Navigate to your working directory and execute all files from that location.

Execute the tutorial setup which requires access to the SH user.

Assumptions
This tutorial assumes the following:
1 - you have installed the sales history sample schema. There is more information about
how to install the sample schemas in the Oracle 12xc Database documentation.
Following this
linkhttps://docs.oracle.com/database/121/COMSC/installation.htm#COMSC00001. See
the section headed "Installing the SH Schema"
2 - you have run all the setup scripts before trying to execute any of the SQL scripts.
The SQL commands incementally add new features and functions, however, it is not
necessary to complete/run each script. Each script works in isolation so you do need to
work through an entire topic before going to another one.

Tutorial Overview
Note that the generated data used in the tutorial is contained within the SH user schema
so your query results should match the example output exactly.
The tutorial is broken down into a number of different stages:

Analytical SQL Part 1

Analytical SQL Part 2

Analytical SQL Part 3

Pivoting and unpivoting data

Top-N queries

Aggregating data using cubes and rollups

Setup

Set up the tutorial by running the following scripts. These scripts do not form part of the
tutorial, they create additional tables and views used by the scripts.

1-0_setup.sql

1-1_Setup_analytical_funtions.sql

1-2_Setup_Cubes_Rollups.sql

1-3_pivoting_setup.sql

This assumes that you have installed the sales history sample schema which creates
the user SH. More information about how to install the sales history schema is included
in the section headed "Assumptions".

Exercises
There is an additional readme.md file in the "Scripts" directory that will provide you with
more information about how to run each set of examples.

S-ar putea să vă placă și