개인적인 정리

Oracle LAST_VALUE() 본문

DB/ORACLE

Oracle LAST_VALUE()

yeon.Biju 2020. 4. 6. 16:11

오라클 LAST_VALUE()

 

LAST_VALUE()

   - 

 

LAST_VALUE(expr) OVER (analytic_clause

LAST_VALUE(expr RESPECT|IGNORE NULL) OVER (analytic_clause

의 형태

 

LAST_VALUE is an analytic function that is useful for data densification. It returns the last value in an ordered set of values.

{RESPECT | IGNORE} NULLS determine whether null values of expr are included in or eliminated from the calculation. the default is RESPECT NULLS. If the last value in the set is null, then the function returns NULL unless you specify IGNORE NULLS, then LAST_VALUE returns thea last non-null value in the set, or NULL if all values are null. 

 

You cannot nest analytic functions by using LAST_VALUE or any other analytic function for expr. However, you can use other built-in function expressions for expr.

 

If you omit the windowing_clause of the analytic_clause, it defaults to RANGE BETWEEN UNBOUNDED PRECDEING AND CURRENT ROW. This default sometimes returns an unexpected value, because the last value in the window is at the bottom of the window, which is not fixed. It keeps changing as the current row changes. For expected results, specify the windowing_clause as RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING. Alternatively, you can specify the windowing_clause as RANGE BETWEEN CURRNET ROW UNBOUNDED FOLLOWING.

 

SQL >
SELECT
    last_name,
    salary,
    hire_date,
    LAST_VALUE(hire_date) OVER(ORDER BY salary ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS lv
FROM (SELECT * FROM employees where department_id=90 order by hire_date) 

 

 

'DB > ORACLE' 카테고리의 다른 글

Oracle LN()  (0) 2020.04.08
Oracle LISTAGG()  (0) 2020.04.08
Oracle LENGTH()  (0) 2020.04.07
Oracle LEAD()  (0) 2020.04.07
ORACLE LAST_DAY()  (0) 2020.04.06
ORACLE LAST()  (0) 2020.04.06
Oracle INSTR()  (0) 2020.04.06
Oracle INSERTCHILDXML()  (0) 2020.04.06
Comments