有没有办法使用plsql以降序迭代游标?
我试过了:
FOR item IN REVERSE items
LOOP
-- do stuff
END LOOP;
但它似乎忽略了反向关键词。
有什么建议吗?
答案 0 :(得分:6)
SQL子句确定遍历数据的顺序,因此只需在查询中应用适当的ORDER BY。
答案 1 :(得分:0)
DECLARE
cursor c1 is Select * FROM table_1
where (something)
order by (id..whatever you want) DESC; --decrement
v_variable.table%rowtype;
BEGIN
open c1;
fetch c1 into variable; -- will fetch first row...but it will be DESC
close c1;
END;
那样的......
OR
FOR i1 IN c1
LOOP
i1.id...
something...
END LOOP;
OR
FOR i2 IN (Select * FROM table_1
where (something)
order by (id..whatever you want) DESC)
LOOP
--something
END LOOP;
答案 2 :(得分:0)
由于您没有任何要订购的列,请尝试使用rownum的订单