user1856981
user1856981

Reputation: 19

PL/SQL Script to add value in the next row

i have a Select which contains a Object and a specific track information. example:

OBJECT  ANK      ABF    LAUFNR
661             19:09   3
661             19:18   6
661     19:20   19:22   7
661     19:23           8

now i need a PL/SQL which takes the value ABF and add's the Value to the next row in field ANK example:

OBJECT  ANK      ABF    LAUFNR
661             19:09   3
661     19:09   19:18   6
661     19:18   19:22   7
661     19:23           8

the PL/SQL should work with the SQL.

also i have another SQL without a Number

what I meant above: i have 2 SQL (both with rownum) by the 2nd i have rownum +1 and i matched both to come to the result. my idea was to have a PL/SQL script .... because i have another selects without any number (example- laufnr in the select above) example without a number

OBJECT  from       To
661     H   H1     Sns
661                Jb
661                Bri H1
661     Bri H1     Bri
661                Rdf H1
661     Rdf H1     Rdf

Thanks

Upvotes: 0

Views: 211

Answers (1)

peter.hrasko.sk
peter.hrasko.sk

Reputation: 4141

select object,
    nvl(ank, lag(abf) over (partition by object order by laufnr) as ank,
    abf, laufnr
from your_table
;

This will select the data for you. If you need to update the your_table with the data, it will be a slightly different query.

Upvotes: 1

Related Questions