This is in the Oracle documentation for Aggregate Functions:
All aggregate functions except COUNT(*)
, GROUPING
, and GROUPING_ID
ignore null
s. You can use the NVL
function in the argument to an aggregate function to substitute a value for a null
. COUNT
and REGR_COUNT
never return null
, but return either a number or zero. For all the remaining aggregate functions, if the data set contains no rows, or contains only rows with null
s as arguments to the aggregate function, then the function returns null
.
When you look at the documentation for Analytic Functions it states:
Analytic functions compute an aggregate value based on a group of rows. They differ from aggregate functions in that they return multiple rows for each group.
So an analytic function will follow exactly the same rules for null
values as its equivalent aggregate version (and will ignore null
values except in those documented cases); and will applying the aggregation over a window and return multiple rows.
For example, if you have the sample data:
CREATE TABLE table_name (
id NUMBER GENERATED ALWAYS AS IDENTITY,
column_name NUMBER
);
INSERT INTO table_name (column_name) VALUES (NULL);
INSERT INTO table_name (column_name) VALUES (NULL);
Then:
SELECT id, MAX(column_name) OVER () FROM table_name;
Outputs:
ID |
MAX(COLUMN_NAME)OVER() |
1 |
null |
2 |
null |
Then it outputs null
as the data-set contains only rows with null
s as arguments (exactly as per the documentation).
If you add a non-null
row:
INSERT INTO table_name (column_name) VALUES (42);
Then:
SELECT id, MAX(column_name) OVER () FROM table_name;
Outputs:
ID |
MAX(COLUMN_NAME)OVER() |
1 |
42 |
2 |
42 |
3 |
42 |
Again, exactly as documented, the null
values are ignored and the maximum of the non-null
rows is returned.
fiddle