如何循环遍历不同的模式并在每个模式上执行一些sql?

发布于 2024-10-21 19:57:07 字数 374 浏览 18 评论 0原文

我有一个案例,我有 70 个 Oracle 模式,我必须在每个模式上执行相同的脚本

,这将是实现此目的的最佳方法。

可以用游标吗?

现在我用

ALTER SESSION SET current_schema = SCHEMA_1;
====
ALTER SESSION SET current_schema = SCHEMA_2;
====
ALTER SESSION SET current_schema = SCHEMA_3;
====

我的脚本替换“====”,我用Notepad++做它,但我必须手动准备脚本,如果脚本很长,我必须将它分成多个没有新行的块并对每个块进行替换

我想将其自动化一点。

I have a case where I have 70 oracle schemas and I have to execute the same script on each

which would be the best way to achieve this.

Is it possible with a CURSOR?

For now I'm doing it with

ALTER SESSION SET current_schema = SCHEMA_1;
====
ALTER SESSION SET current_schema = SCHEMA_2;
====
ALTER SESSION SET current_schema = SCHEMA_3;
====

And I replace the "====" with my script, I+m doing it with Notepad++ but I have to prepare the script manually and if the script is long I have to split it in multiple chunks without new lines and do a replace for each chunk

I would like to automate this a little bit more.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱本泡沫多脆弱 2024-10-28 19:57:07

我提供以下半自动方式,它不会自动执行您的任务,但会减少搜索和替换。

如果您使用的是 SQL*Plus,则可以使用以下语法执行文件:

@myscriptfile.sql

如果您想对每个模式执行一次,您可以通过查询字典来生成代码:

select 'ALTER SESSION SET current_schema = ' || owner || ';
       @myscriptfile.sql'
  from dba_users
 where <your filter>;

然后您只需复制/粘贴结果sqlplus 中的查询。可能可以将其假脱机归档并执行。

I offer the following semi-automatic way, which does not automate your task, but cuts down on the search and replace.

If you are using SQL*Plus, you can execute a file with the following syntax:

@myscriptfile.sql

If you would want to do that once for each schema, you could generate the code by querying the dictionary:

select 'ALTER SESSION SET current_schema = ' || owner || ';
       @myscriptfile.sql'
  from dba_users
 where <your filter>;

Then you would just copy/paste the result of that query in sqlplus. It is probably possible to spool that to file and execute it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文