在另一个 plsql 脚本中调用 plsql 脚本

发布于 2024-10-04 18:36:13 字数 361 浏览 2 评论 0原文

我有一个充满我想要运行的 PLSQL 脚本的目录,问题是该目录的内容是动态的,我无法知道这些脚本的名称是什么。

我必须编写一些东西来运行该目录中的所有 sql 文件,但我无法在 PLSQL 中找到调用文件名在运行时未知的脚本的方法。

我尝试了一些东西,例如将 .sql 文件内容加载到 VARCHAR2 中,然后执行

EXECUTE IMMEDIATE l_Script_Content;

但由于某种原因这不起作用,我想必须有一种更简单的方法来做到这一点,比如突然 @ 命令接受 varchar2 而不是完整的小路。

有人能指出我正确的方向吗?也许从java运行脚本?

谢谢!

I have a directory full of PLSQL scripts that I want to run, the problem is that the content of that directory is dynamic, and I have no way to know what the names of those scripts will be.

I have to write some stuff to run all of the sql files in that directory, but I can't find a way in PLSQL of call a script which file name is unknown until runtime.

I tried some stuff like load the .sql file content into a VARCHAR2 and then do

EXECUTE IMMEDIATE l_Script_Content;

But for some reason this just doesn't work, I guess there has to be a easier way to do that, like suddenly @ command accepting varchar2 instead a full path.

Can anyone point me in the right direction? Maybe running the scripts from java?

Thanks!

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

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

发布评论

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

评论(2

谁的新欢旧爱 2024-10-11 18:36:14

PL/SQL 不是适合这项工作的工具。最简单的方法是使用某种 shell 脚本(例如 BASH)来构建 SQL 文件并运行它。
像这样:


bash> EXPORT IFS="
"
bash> for FILE in `ls -1 *.pls``;  # single backtick here -_-
  do echo "start "$FILE >> run.sql;
done;

sqlplus>启动run.sql

PL/SQL is not the right tool for the job. The easiest way would be to use some kind of shell scripting (BASH for example) to build an SQL file and run that.
like this:


bash> EXPORT IFS="
"
bash> for FILE in `ls -1 *.pls``;  # single backtick here -_-
  do echo "start "$FILE >> run.sql;
done;

sqlplus> start run.sql

丶视觉 2024-10-11 18:36:14

将此安装脚本保存在同一文件夹中,例如“current_folder_location/”,其中所有 plsql 文件都以 .sql 格式存在。
您可以在 unnixbox、sqlplus、sql Developer 中触发此操作:

set define off;
spool install_scripts_logs.log;

Prompt plsql_file_1.sql
@current_folder_location/plsql_file_1.sql
show errors;

Prompt plsql_file_2.sql
@current_folder_location/plsql_file_2.sql
show errors;

Prompt plsql_file_1.sql
@current_folder_location/plsql_file_2.sql
show errors;

spool off;

Save this install script in the same folder eg-"current_folder_location/" where all your plsql file exits- in .sql format.
You can trigger this in unnixbox, sqlplus, sql Developer:

set define off;
spool install_scripts_logs.log;

Prompt plsql_file_1.sql
@current_folder_location/plsql_file_1.sql
show errors;

Prompt plsql_file_2.sql
@current_folder_location/plsql_file_2.sql
show errors;

Prompt plsql_file_1.sql
@current_folder_location/plsql_file_2.sql
show errors;

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