Postagens populares

Oh vida "vea" boa

quarta-feira, 10 de novembro de 2010

Oracle: Previous, current and next values

Oracle: Previous, current and next values

The Oracle lag and lead functions can be used to retrieve values from a previous row (lag) or a next row (lead). Consider the following example.


SQL> select deptno
2 , lag(deptno) over (order by deptno) as previous
3 , lead(deptno) over (order by deptno) as next
4 from scott.dept
5
SQL> /

DEPTNO PREVIOUS NEXT
------ ---------- ----------
10 20
20 10 30
30 20 40
40 30