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

Term: LAST

Definition:
The Oracle PL/SQL function LAST is used to return the last value from an ordered sequence. It can be used for both aggregate and analytic action on a group of logically sorted rows. It operates on values of these rows that are eligible to be ranked first or last. The rows can be grouped using any of the analytic functions like MIN, MAX, SUM, AVG, COUNT, VARIANCE or STDDEV.

Example Syntax:

[AGGREGATE FUNCTION] KEEP (DENSE_RANK LAST ORDER BY [COLUMN | EXPRESSION] [ASC | DESC] )
OVER (PARTITION BY [COLUMN] )


In the syntax, KEEP keyword is used as an indication that only LAST values are returned. Note that DENSE_RANK is ranks the grouped rows and used to extract minimum or maximum value.

Example Usage:

SELECT
MAX(city) KEEP (DENSE_RANK FIRST ORDER_BY SUM(temperature))
AS highest_temp,
MIN(city) KEEP (DENSE_RANK LAST ORDER_BY SUM(temperature))
AS lowest_temp
FROM temperature_log
GROUP_BY city
ORDER_BY city;



Related Links:

Related Code Snippets:
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 68 users online    © 2009 psoug.org
PSOUG LOGIN
Username: 
Password: 
Forgot your password?