Category: Oracle database tutorial
-
Cumulative Spend per Customer per Month in Oracle
1. Introduction In many analytical and financial systems, you often need to calculate how much a customer has spent over time — either within a month (running total) or across months (year-to-date cumulative spend). For example: This is a classic window function (analytic function) use case in Oracle. 2. Example Table Let’s start with a…
-
Detecting gaps in sequential data
1. Introduction In many business applications, you may have tables containing sequential values, such as: However, due to missing records, data corruption, or load errors, some IDs or dates may be missing. Detecting these gaps is a very common data quality check. In Oracle, there are several ways to identify these gaps using SQL. 2.…
-
Transpose rows into columns using case and without case
1. Introduction: What is Transposing Rows into Columns? When you transpose rows into columns, you’re converting row values into multiple columns. This is often needed in reporting, data aggregation, or visualization where you want each unique value in a column (like department or month) to become a separate column. Example Input Table Let’s take an…
-
Query Execution Plan in Oracle
1. What Is a Query Execution Plan? A Query Execution Plan (often called EXPLAIN PLAN) in Oracle shows the sequence of operations that the Oracle optimizer chooses to execute a SQL statement.It describes how Oracle will access the data — which indexes will be used, which tables will be joined, and in what order. Think…
-
ROWID in Oracle
What is ROWID? ROWID is a pseudocolumn in Oracle that uniquely identifies the physical location of a row in a table. Characteristics of ROWID Feature Description Unique Each row has a unique ROWID within the database. Physical Address Contains data object number, datafile, block, and row position. Read-Only Cannot be updated or modified by users.…
-
ROW_NUMBER()
What is ROW_NUMBER()? ROW_NUMBER() is an analytic function in Oracle SQL that assigns a unique sequential number to each row within a result set or partition, based on a specific order. Unlike the ROWNUM pseudocolumn (which is assigned before sorting), ROW_NUMBER() is assigned after the ORDER BY clause, which makes it more reliable for pagination,…
-
ROWNUM in Oracle
What is ROWNUM? ROWNUM is a pseudocolumn in Oracle SQL that assigns a unique, sequential number to each row returned by a query result. Syntax You can also filter rows using ROWNUM: This fetches only the first 5 rows returned by the query. Important Behavior of ROWNUM Rule Explanation 1 ROWNUM is assigned after WHERE…
-
PIVOT Operator
Oracle SQL’s PIVOT clause allows you to transform row data into columns. It’s particularly useful when summarizing data across multiple categories, such as months, departments, or product types. 1. What Is Pivoting? Pivoting is the process of converting rows into columns to better analyze or report on grouped data. Example Scenario: Imagine you have a…
-
PARTITION BY Clause
In Oracle SQL, the PARTITION BY clause is used with analytic (window) functions to divide the result set into groups or partitions, over which the analytic function is applied independently. This is similar to how GROUP BY works in aggregate functions, but with one major difference: GROUP BY collapses rows into one per group, whereas…
-
DENSE_RANK() Function
The DENSE_RANK() function is an analytic (window) function in Oracle SQL that assigns ranks to rows in an ordered set without gaps in ranking values, even when there are ties. It is especially useful when you want to generate rankings with continuous numbers, even for rows with duplicate values. 1. Syntax Parameters: 2. Key Features…
