在将这个匿名块创建到过程中时,我需要帮助。 我是PLSQL的新手。任何帮助都感激不尽。先感谢您。 我希望此查询仅通过调用过程即可运行。
TRUNCATE TABLE dblink_status_tbl;
set serveroutput on;
-- or equivalent for your client
declare
-- l_dummy dual.dummy%type;
l_dummy VARCHAR2(20);
l_status VARCHAR2(100);
begin
for r in
(select db_link from all_db_links where db_link in
( 'WP1',
'6P1',
'OP3',
'LP1',
'ODS')
and owner = 'CAMPER')
loop
begin
execute immediate 'select 1 from dual@' || r.db_link into l_dummy;
l_status:= 'ACTIVE';
dbms_output.put_line(r.db_link|| ',' || l_status);
rollback work;
execute immediate 'alter session close database link ' || r.db_link;
exception
when others then
l_status:= sqlerrm;
l_status := replace(replace(l_status,CHR(13), ' '),CHR(10),' ');
l_status := '"' || l_status || '"';
dbms_output.put_line(r.db_link|| ',' || l_status);
end;
insert into dblink_status_tbl
values(r.db_link,l_status);
commit;
end loop;
end;
答案 0 :(得分:2)
基本上,您在示例中仅需要第一行:
create or replace procedure p_your_proc as
-- from now on, it is your original code
l_dummy VARCHAR2(20);
l_status VARCHAR2(100);
begin
...
end;
/
一旦创建,就以
运行begin
p_your_proc;
end;
/
PS
在一开始,您将截断一个表-如果该过程中有必要,则将使用动态SQL(因为它是DDL):
begin
execute immediate ('TRUNCATE TABLE dblink_status_tbl');
...
end;
或者,只需将其内容删除为
begin
delete from dblink_status_tbl;
...
end;
答案 1 :(得分:1)
使其具有某种特征:
Invoices
像这样运行:
“执行过程名称”或“执行过程名称”