日期:2014-05-17  浏览次数:20768 次

如何在数据库上执行存贮过程。。。?
本机连到远程Oracle数据库,需要特殊设置网络才能连上。

有时晚上执行某个存贮过程早上来发现网络断的情况,存贮过程没跑完,我想直接在数据上去执行,就不会出现因网络问题中断的情况。

不知道要怎么做?请赐教!

------解决方案--------------------
lz,用job
下面是详细的使用job的实例:

SQL> create table a(a date);
Table created
创建一个过程
create or replace procedure kill_inactivate_SESSION is
cursor cur_session is
select s.sid, s.serial#
from v$session s, v$session_wait sw
where s.sid = sw.sid
and s.status = 'INACTIVE '
--and s.username in (select user_name from gusermgr.gbs_user_tbl)
and s.last_call_et > = 3600
and sw.event = 'SQL*Net message from client ';
v_sid v$session.sid%type;
v_serial v$session.serial#%type;
v_sqlstr varchar2(63);
v_errmsg varchar2(63);
begin
v_sqlstr := 'alter system kill session ' ' ';
v_errmsg := 'is killed because it is INACTIVE for longer than 1 hour. ';
open cur_session;
loop
fetch cur_session into v_sid, v_serial;
exit when cur_session%NOTFOUND;
execute immediate v_sqlstr||v_sid|| ', '||v_serial|| ' ' ' ';
DBMS_OUTPUT.PUT_LINE( 'SESSION( '||v_sid|| ', '||v_serial|| ') '||v_errmsg);
end loop;
close cur_session;
return;
end kill_inactivate_SESSION;

Procedure created


提交作业
SQL> variable n number;
SQL> begin
2 dbms_job.submit(:n, 'kill_inactivate_session; ',sysdate, 'sysdate+1 ');
3 commit;
4 end;
5 /

PL/SQL procedure successfully completed
n
---------
514