Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 The Oracle PL/SQL LAG Function      [Return To Index] Jump to:  
  Looking for the original pages? (formerly called "Morgan's Library") You can find them here.

Term: LAG

Definition:
The Oracle LAG function is an analytic function through which one can access the preceding row, without making any self join. It is normally used to get the value of an attribute of the previous row. Until unspecified, LAG can access one offset row prior to the cursor's current position.

(If you need to retrieve a value from the next row, use LEAD instead of LAG.)

Example Syntax:

LAG(value_expression [,offset] [,default]) OVER ([query_partition_clause] order_by_clause)


The default value is returned in case the offset moves the cursor position beyond the scope of the result set. It is NULL by default.

Example Usage:

SELECT EMPNO, ENAME, SALARY,
LAG(SALARY, 1, 0) OVER (ORDER BY SALARY) AS LAST_SAL,
FROM EMPLOYEES;



Related Links:

Related Code Snippets:
  • LAG - LAG provides access to more than one row of a table at the same time without a self-join. Gi...
  • Lag Report - A sample of a payment lag report.
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 59 users online    © 2009 psoug.org
PSOUG LOGIN
Username: 
Password: 
Forgot your password?