dblink в многопоточном режиме

Входные параметры процедуры: nCOUNT — количество потоков, sNAME_ACTION — имя процедуры, функции. Берется количество dblink ‘ов делится на количество потоков и с помощью пагинации (Pagination) выполняется действие sNAME_ACTION с входным параметром-имя ссылки.

create or replace procedure RAD_P_THREAD_LINK(nCOUNT in number default 1,
sNAME_ACTION in varchar2) as

nJOBS number;
nLINKS number;
nPAGINATION number;

procedure P_JOB_SESSION(sACTION in varchar2) as
nCNT number;
begin
begin
--select 1 into nCNT from v$session v where v.ACTION = sACTION;
SELECT 1
into nCNT
FROM USER_SCHEDULER_JOBS
WHERE job_name = sACTION
AND STATE = 'RUNNING';
exception
when others then
nCNT := 0;
end;
if (nCNT > 0) then
SYS.DBMS_LOCK.SLEEP(5);
--рекурсия
P_JOB_SESSION(sACTION);
end if;
end P_JOB_SESSION;

procedure P_CREATE_JOB(sNAME in varchar2, nPAGI in number, i integer) as
nMAX_ROW number;
MIN_ROW number;
sJOB_ACTION varchar2(500);
begin
nMAX_ROW := nPAGI * i;
MIN_ROW := nMAX_ROW - nPAGI;
sJOB_ACTION := 'begin
for lnks in (select db_link
from (select a.*, rownum rnum
from (select t.db_link from dba_db_links t) a
where rownum <= ' || nMAX_ROW || ') where rnum >= ' || MIN_ROW || ' ) loop
' || sNAME_ACTION || '(lnks.db_link);
end loop;
end;';
sys.dbms_scheduler.create_job(job_name => sNAME,
job_type => 'PLSQL_BLOCK',
job_action => sJOB_ACTION);
end;

procedure P_RUN_JOB(sNAME in varchar2) as
begin
dbms_scheduler.run_job(sNAME, false);
end;

procedure P_DROP_JOB(sNAME in varchar2) as
begin
begin
dbms_scheduler.drop_job(sNAME, TRUE);
exception
when others then
null;
end;
end;

begin
nJOBS := nCOUNT;
select count(*) into nLINKS from dba_db_links;
if (nLINKS > nJOBS) then
nPAGINATION := CEIL(nLINKS / nJOBS);
else
nJOBS := 1;
nPAGINATION := nLINKS;
end if;

for i in 1 .. nJOBS loop
P_DROP_JOB('JOB_UPD_' || i);
end loop;

for i in 1 .. nJOBS loop
P_CREATE_JOB('JOB_UPD_' || i, nPAGINATION, i);
end loop;

for i in 1 .. nJOBS loop
P_RUN_JOB('JOB_UPD_' || i);
end loop;

SYS.DBMS_LOCK.SLEEP(5);

for i in 1 .. nJOBS loop
P_JOB_SESSION('JOB_UPD_' || i);
end loop;

for i in 1 .. nJOBS loop
P_DROP_JOB('JOB_UPD_' || i);
end loop;

end RAD_P_THREAD_LINK;