© 2020

Practical Oracle SQL

Mastering the Full Power of Oracle Database


Table of contents

  1. Front Matter
    Pages i-xxiii
  2. Core SQL

    1. Front Matter
      Pages 1-1
    2. Kim Berg Hansen
      Pages 3-16
    3. Kim Berg Hansen
      Pages 17-38
    4. Kim Berg Hansen
      Pages 39-56
    5. Kim Berg Hansen
      Pages 57-71
    6. Kim Berg Hansen
      Pages 73-85
    7. Kim Berg Hansen
      Pages 107-129
    8. Kim Berg Hansen
      Pages 131-144
    9. Kim Berg Hansen
      Pages 145-168
    10. Kim Berg Hansen
      Pages 169-190
  3. Analytic Functions

    1. Front Matter
      Pages 191-191
    2. Kim Berg Hansen
      Pages 193-213
    3. Kim Berg Hansen
      Pages 215-235
    4. Kim Berg Hansen
      Pages 237-265
    5. Kim Berg Hansen
      Pages 267-286
    6. Kim Berg Hansen
      Pages 287-305
    7. Kim Berg Hansen
      Pages 307-322
  4. Row Pattern Matching

    1. Front Matter
      Pages 323-323

About this book


Write powerful queries using as much of the feature-rich Oracle SQL language as possible, progressing beyond the simple queries of basic SQL as standardized in SQL-92.

Both standard SQL and Oracle’s own extensions to the language have progressed far over the decades in terms of how much you can work with your data in a single, albeit sometimes complex, SQL statement. If you already know the basics of SQL, this book provides many examples of how to write even more advanced SQL to huge benefit in your applications, such as:
  • Pivoting rows to columns and columns to rows
  • Recursion in SQL with MODEL and WITH clauses
  • Answering Top-N questions
  • Forecasting with linear regressions
  • Row pattern matching to group or distribute rows
  • Using MATCH_RECOGNIZE as a row processing engine
The process of starting from simpler statements in SQL, and gradually working those statements stepwise into more complex statements that deliver powerful results, is covered in each example. By trying out the recipes and examples for yourself, you will put together the building blocks into powerful SQL statements that will make your application run circles around your competitors.

You will:
  • Take full advantage of advanced and modern features in Oracle SQL
  • Recognize when modern SQL constructs can help create better applications
  • Improve SQL query building skills through stepwise refinement
  • Apply set-based thinking to process more data in fewer queries
  • Make cross-row calculations with analytic functions
  • Search for patterns across multiple rows using row pattern matching
  • Break complex calculations into smaller steps with subquery factoring


Advanced SQL Oracle SQL Analytic Functions Window Functions Subquery Factoring Pivot Queries Pivot Unpivot SQL Pivoting Row Pattern Matching MATCH_RECOGNIZE Analytic Views MODEL Clause Recursion and the WITH Clause Multiset Operators Binning

Authors and affiliations

  1. 1.MiddelfartDenmark

About the authors

Kim Berg Hansen is a database developer from Middelfart in Denmark. As a youngster he originally wanted to work with electronics, and he tried computer programming and discovered that the programs he wrote worked well—unlike the electronics projects he soldered that often failed. This led to a VIC-20 with 5 kilobytes RAM and many hours programming in Commodore Basic.

Having discovered his talent, Kim financed computer science studies at Odense University with a summer job as sheriff of Legoredo, while learning methodology and programming in Modula-2 and C. From there he moved into consulting as a developer making customizations to ERP software. That gave him his first introduction to Oracle SQL and PL/SQL, with which he has worked extensively since the year 2000.

His professional passion is to work with data inside the database utilizing the SQL language to the fullest to achieve the best application experience for his application users. With a background fitting programs into 5 KB RAM, Kim hates to waste computing resources unnecessarily.

Kim shares his experience and knowledge by blogging at the website, presenting at various Oracle User Group conferences, and being the SQL quizmaster at the Oracle Dev Gym. His motivation comes from peers who say “now I understand” after his explanations, and from end users who “can’t live without” his application coding. He is a certified Oracle OCE in SQL, and an Oracle ACE Director. 

Outside the coding world, Kim is married, loves to cook, and is a card-carrying member of the Danish Beer Enthusiasts Association.

Bibliographic information

Industry Sectors
Chemical Manufacturing
IT & Software
Consumer Packaged Goods
Materials & Steel
Finance, Business & Banking
Energy, Utilities & Environment