sql - Getting data from the next row in Oracle cursor -


I am creating a nested tree and I have to get data for the next line in the cursor using Oracle. And I still need an existing line, so proceeding is not a solution example:

  open emp_cv for sql_stmt; Loop Fetch emp_cv in v_rcod, v_rname, v_level; Remove when emp_cv% NOTFOUND; / * Here v_next_level * / if v_next_level & gt; The code to get is V_level then / * code here * / elsif v_next_level & lt; V_level then / * here code * / else / * here code * if / end; End loop; Close emp_cv;  

Use lead and leg actions

Seed has the ability to calculate an expression on the next rows (the rows that are coming after the current line) and return the value to the current line The general syntax of the lead is shown below:

Lead (sql_expr, offset, default) Over (Analytic_clave)

sql_expr is the expression to calculate the leading line

Offset is the leading line index relative to the current row. Offset is a positive integer with the default.

The syntax of the lag is similar to that the offset for the lag goes to the previous rows. Select DEPOTO, IMPO, SEAL, LEAD (SAL, 1, 0) OVER (by order by department DESC) NEXT_LOW_SAL, LAG (SAIL, 1, 0) OVER (DEPARTMENT) Order by DEC) PREV_HIGH_SAL from emp WHERE deptno IN (10, 20) order by deptno, sal DESC; DEPTNO EMPNO SAL NEXT_LOWER_SAL PREV_HIGHER_SAL ------- ------ ----- -------------- ------------- - 10 7839 5000 2450 0 10 7782 2450 1300 5000 10 7934 1300 2450 20 7788 3000 3000 0 20 7902 3000 2975 3000 20 7566 2975 1100 3000 20 7876 1100 800 2975 20 7369 800 0 1100 8 Selected rows


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -