如何循环遍历不同的模式并在每个模式上执行一些sql?
我有一个案例,我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我提供以下半自动方式,它不会自动执行您的任务,但会减少搜索和替换。
如果您使用的是 SQL*Plus,则可以使用以下语法执行文件:
如果您想对每个模式执行一次,您可以通过查询字典来生成代码:
然后您只需复制/粘贴结果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:
If you would want to do that once for each schema, you could generate the code by querying the dictionary:
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.