I need to create a seemingly simple procedure in Oracle SQL, yet I struggle to do it. It has to run the same query over and over again in an infinite loop. And the results of that query should be printed out. I used sys_refcursor for this and wrote this procedure:
CREATE OR REPLACE PROCEDURE writer
AS
rc sys_refcursor;
BEGIN
LOOP
open rc for 'select (select username from v$session where sid=a.sid) blocker, a.sid, (select username from v$session where sid=b.sid) blockee, b.sid from v$lock a, v$lock b where a.block = 1 and b.request > 0 and a.id1 = b.id1 and a.id2 = b.id2';
dbms_sql.return_result(rc);
close rc;
SYS.dbms_session.sleep(1);
END LOOP;
END;
Which is incorrect, because as I learned you can't open the same cursor several times. So how should I approach this? Is there a way to do it with cursor, or maybe some other method?