在另一个 plsql 脚本中调用 plsql 脚本
我有一个充满我想要运行的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PL/SQL 不是适合这项工作的工具。最简单的方法是使用某种 shell 脚本(例如 BASH)来构建 SQL 文件并运行它。
像这样:
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:
sqlplus> start run.sql
将此安装脚本保存在同一文件夹中,例如“current_folder_location/”,其中所有 plsql 文件都以 .sql 格式存在。
您可以在 unnixbox、sqlplus、sql Developer 中触发此操作:
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: