ORACLE/PLSQL: LEAD FUNCTION This Oracle tutorial explains how to use the Oracle/PLSQL LEAD function with syntax and examples.
DESCRIPTION The Oracle/PLSQL LEAD function is an analytic function that lets you query more than one row in a table at a time without having to join the table to itself. It returns values from the next row in the table. To return a value from a previous row, try using the LAG function.
SYNTAX The syntax for the Oracle/PLSQL LEAD function is: LEAD ( expression [, offset [, default] ] ) over ( [ query_partition_clause ] order_by_clause )
Parameters or Arguments expression is an expression that can contain other builtin functions, but can notcontain any analytic functions. offset is optional. It is the physical offset from the current row in the table. If this parameter is omitted, the default is 1. default is optional. It is the value that is returned if the offset goes out of the bounds of the table. If this parameter is omitted, the default is null.
APPLIES TO The LEAD function can be used in the following versions of Oracle/PLSQL: Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i
EXAMPLE The LEAD function can be used in Oracle/PLSQL. Let's look at an example. If we had an orders table that contained the following data: