totn Oracle Functions

Oracle / PLSQL: MEDIAN Function

This Oracle tutorial explains how to use the Oracle/PLSQL MEDIAN function with syntax and examples.

Description

The Oracle/PLSQL MEDIAN function returns the median of an expression.

Syntax

The syntax for the MEDIAN function in Oracle/PLSQL is:

MEDIAN( expression ) [ OVER ( query partition clause ) ]

Parameters or Arguments

expression
The value used to calculate the median.

Returns

The MEDIAN function returns a numeric or date value.

Note

  • The MEDIAN function is NEW to Oracle 10! In older versions of Oracle, try using the PERCENTILE_CONT function to calculate the median value.

Applies To

The MEDIAN function can be used in the following versions of Oracle/PLSQL:

  • Oracle 12c, Oracle 11g, Oracle 10g

Example

Let's look at some Oracle MEDIAN function examples and explore how to use the MEDIAN function in Oracle/PLSQL.

For example:

select MEDIAN(salary)
from employees
where department = 'Marketing';

The SQL statement above would return the median salary for all employees in the Marketing department.