Skip to content

nnamacha/analytical-sql-examples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

analytical-sql-examples

The aim of this reopistory is to provide some simple code samples for Oracle's analytical SQL features, such as the following:

  • Window functions
  • Pivot/Unpivot
  • Top-N
  • SQL aggregation extensions: cube, rollup, grouping sets
  • Pattern Matching
  • SQL Model clause

To run these scripts you will need to install the Oracle Sales History schema which is included in the Oracle Database Examples download. There are full instructions on how to install the SH (Sales History) scheman in the "Database Sample Schemas" documentation. There are two ways to install the SH schema:

  1. Using the Database Configuration Assistant When you install Oracle Database with the Oracle Universal Installer, all the sample schemas are installed by default - assuming that you or your DBA selected the Basic Installation option. Selecting the sample schemas option installs all five of our sample schemas (HR, OE, PM, IX, and SH) in the database. If you choose not to install the sample schemas at that time, you can manually add them later.

  2. Manually Installing Sample Schemas If you decide not to install the sample schemas at the time of your initial database installation using DBCA, then you can also create the sample schemas manually by running SQL scripts. Install Oracle Database Examples (Companion CD, part of the media kit) to include these scripts in the demo directory under $ORACLE_HOME.

How to add the SH Schema into your database instance:

All scripts necessary to create the Sales History (SH) schema reside in $ORACLE_HOME/demo/schema/sales_history.

There is only one script to call which is sh_main.sql. This script creates all the schema objects and loads the data into the dimension and fact tables. When you run the script sh_main.sql you will be prompted for the sys password, tablespace names that you want to use, the directory for the database datafiles and the directory for storing the log file generated by the script.

If the SH schema is already installedn then the script checks for this and removes the existing schema objects and related users. After the sh_main.sql script runs successfully and the SH schema is installed, you are connected as the user SH. To verify that the schema was created, use the following command:

SQL> SELECT table_name FROM user_tables;

You can check that the following tables are present and populated with data: dimension tables TIMES, CHANNELS, PROMOTIONS, CUSTOMERS, PRODUCTS and the fact table SALES. These are the main tables used in the analytical SQL scripts.

About

Code samples for Oracle's analytical SQL features

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PLSQL 100.0%