I have a need to stop Oracle query. In pl/sql my task looks like
To explain the idea: I'm moving through some table by index and check some condition. When it becomes true I'm stopping. Is it possible in plain SQL query?
Regards, Dima
Code:
declare
lTestDate date;
begin
--moving through a cursor
for f in (select /*+ first_rows*/
id, prev_id, time_stamp
from my_table
order by id desc) loop
--checking some condition
if f.prev_id <> f.id then
select time_stamp
into lTestDate
from my_table
where id = f.prev_id;
else
lTestDate := f.time_stamp;
end if;
--stopping further processing
exit when lTestDate < trunc(sysdate);
end loop;
end;
Regards, Dima