SQL> set serveroutput on
SQL> declare
2 l_str varchar2(200);
3 begin
4 for cur_r in (select link from links) loop
5 l_str := 'insert into db_tracker ' ||
6 'select name from v$database@' || cur_r.link;
7 dbms_output.put_line(l_str);
8
9 -- execute immediate l_str;
10 end loop;
11 end;
12 /
insert into db_tracker select name from v$database@dbl_ora10
insert into db_tracker select name from v$database@dbl_ora11
insert into db_tracker select name from v$database@dbl_orcl
PL/SQL procedure successfully completed.
SQL>
如果你真的想选择 name 在屏幕上显示,然后你需要 into 条款。像这样:
SQL> set serveroutput on
SQL>
SQL> declare
2 l_name varchar2(30);
3 begin
4 for cur_r in (select link from links) loop
5 execute immediate 'select name from v$database@' || cur_r.link
6 into l_name;
7 dbms_output.put_line(l_name);
8 end loop;
9 end;
10 /
XE
PL/SQL procedure successfully completed.
SQL>
1条答案
按热度按时间py49o6xq1#
动态sql。
假设数据库链接存储在
link
表格:然后使用一个循环,创建一个
insert
语句并执行它。因为我没有那些数据库链接,所以我只是在屏幕上显示语句。你应该取消注解execute immediate
线路。如果你真的想选择
name
在屏幕上显示,然后你需要into
条款。像这样: