How can I compute consecutive differences in Oracle SQL without a cursor?

How do I calculate differences between adjacent rows in Oracle SQL without using a cursor? Analytic functions might work. For example:

SELECT num_value,
       num_value - LAG(num_value) OVER (ORDER BY num_value DESC) AS difference
FROM value_set;

hey, ive tried a self join approach using rownum to make sure order stays intact. it was a bit hairy with dupes so i still lean on analytic funcs most times. gives you good perf if your data is clean.

hey guys, i’ve been tinkering with lag function. curoius if analytic functions can act up wit duplicate values sometimes. anyone experimented with self joins instead? what challenges did u face? keen to hr more ideas and experiences.