在 Oracle SQL Developer 中通过相对路径执行脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24002623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Execute scripts by relative path in Oracle SQL Developer
提问by Didjit
First, this question relates to Oracle SQL Developer 3.2, not SQL*Plus or iSQL, etc. I've done a bunch of searching but haven't found a straight answer.
首先,这个问题与Oracle SQL Developer 3.2 相关,而不是 SQL*Plus 或 iSQL 等。我进行了大量搜索,但没有找到直接的答案。
I have several collections of scripts that I'm trying to automate (and btw, my SQL experience is pretty basic and mostly MS-based). The trouble I'm having is executing them by a relative path. for example, assume this setup:
我有几个我正在尝试自动化的脚本集合(顺便说一句,我的 SQL 经验非常基本,并且主要基于 MS)。我遇到的问题是通过相对路径执行它们。例如,假设此设置:
scripts/A/runAll.sql
| /A1.sql
| /A2.sql
|
/B/runAll.sql
/B1.sql
/B2.sql
I would like to have a file scripts/runEverything.sql
something like this:
我想要一个这样的文件scripts/runEverything.sql
:
@@/A/runAll.sql
@@/B/runAll.sql
scripts/A/runAll.sql:
脚本/A/runAll.sql:
@@/A1.sql
@@/A2.sql
where "@@"
, I gather, means relative path in SQL*Plus.
在那里"@@"
,我推测,是指在SQL * Plus相对路径。
I've fooled around with making variables but without much luck. I have been able to do something similar using '&1'
and passing in the root directory. I.e.:
scripts/runEverything.sql:
我一直在制造变量,但运气不佳。我已经能够使用'&1'
和传入根目录来做类似的事情。即:脚本/runEverything.sql:
@'&1/A/runAll.sql' '&1/A'
@'&1/B/runAll.sql' '&1/B'
and call it by executing this:
并通过执行以下命令调用它:
@'c:/.../scripts/runEverything.sql' 'c:/.../scripts'
But the problem here has been that B/runAll.sql
gets called with the path: c:/.../scripts/A/B
.
但这里的问题是B/runAll.sql
被路径调用:c:/.../scripts/A/B
.
So, is it possible with SQL Developerto make nested calls, and how?
那么,SQL Developer 是否可以进行嵌套调用,以及如何进行?
回答by Patrick Bacon
This approach has two components:
这种方法有两个组成部分:
-Set-up the active SQL Developer worksheet's folder as the default directory.
- 将活动 SQL Developer 工作表的文件夹设置为默认目录。
-Open a driver script, e.g. runAll.sql, (which then changes the default directory to active directory), and use relative paths within the runAll.sql script to call sibling scripts.
- 打开驱动程序脚本,例如 runAll.sql,(然后将默认目录更改为活动目录),并使用 runAll.sql 脚本中的相对路径来调用兄弟脚本。
Set-up your scripts default folder. On the SQL Developer toolbar, Use this navigation:
Tools > Preferences
In the preference dialog box, navigate to Database > Worksheet > Select default path to look for scripts.
Enter the default path to look for scripts as the active working directory:
"${file.dir}"
Create a script file and place all scripts associated in it:
runAll.sql
A1.sql
A2.sql
The content of runAll.sql would include:
@A1.sql;
@A2.sql;
设置您的脚本默认文件夹。在 SQL Developer 工具栏上,使用此导航:
工具 > 首选项
在首选项对话框中,导航到数据库 > 工作表 > 选择默认路径以查找脚本。
输入默认路径以查找脚本作为活动工作目录:
“${file.dir}”
创建一个脚本文件并将所有关联的脚本放入其中:
运行所有文件
A1.sql
A2.sql
runAll.sql 的内容将包括:
@A1.sql;
@A2.sql;
To test this approach, in SQL Developer, click on File and navigate and open the script\runAll.sql file.
要测试此方法,在 SQL Developer 中,单击文件并导航并打开 script\runAll.sql 文件。
Next, select all (on the worksheet), and execute.
接下来,全选(在工作表上),然后执行。
Through the act of navigating and opening the runAll.sql worksheet, the default file folder becomes "script".
通过导航和打开 runAll.sql 工作表的操作,默认文件夹变为“脚本”。
回答by Alex Poole
I don't have access to SQL Developer right now so i can't experiment with the relative paths, but with the substitution variables I believe the problem you're seeing is that the positional variables (i.e. &1
) are redefined by each start
or @
. So after your first @runAll
, the parent script sees the same &1
that the last child saw, which now includes the /A
.
我现在无法访问 SQL Developer,因此我无法尝试使用相对路径,但是对于替换变量,我相信您看到的问题是位置变量(即&1
)由 eachstart
或@
. 所以在你的第一个之后@runAll
,父脚本看到的&1
和最后一个孩子看到的一样,现在包括/A
.
You can avoid that by defining your own variable in the master script:
您可以通过在主脚本中定义自己的变量来避免这种情况:
define path=&1
@'&path/A/runAll.sql' '&path/A'
@'&path/B/runAll.sql' '&path/B'
As long as runAll.sql
, and anything that runs, does not also (re-define) path
this should work, and you just need to choose a unique name if there is the risk of a clash.
只要runAll.sql
,以及任何运行的东西,也不会(重新定义)path
这应该起作用,并且如果存在冲突的风险,您只需要选择一个唯一的名称。
Again I can't verify this but I'm sure I've done exactly this in the past...
我再次无法验证这一点,但我确定我过去确实这样做过......
回答by Arpan Saini
you need to provide the path of the file as String , give the patch in double quote it will work
您需要提供文件的路径作为 String ,在双引号中给出补丁它会起作用
**
**
For Example @"C:\Users\Arpan Saini\Zions R2\Reports Statements and Notices\Patch\08312017_Patch_16.2.3.17\DB Scripts\snsp.sql";
例如@"C:\Users\Arpan Saini\Zions R2\Reports Statements and Notices\Patch\08312017_Patch_16.2.3.17\DB Scripts\snsp.sql";
**
**
回答by Lova Chittumuri
Execution of Sql
Sql的执行
@yourPath\yourFileName.sql
回答by Priyanka
How to pass parameters in file
如何在文件中传递参数
@A1.sql; (Parameter)
@A1.sql; (范围)
@A2.sql; (Parameter)
@A2.sql; (范围)
回答by Praveen Kumar
This is not absolute or relative path issue. It's the SQL interpreter issue, where by default it will look for files which are having .sql extention.
这不是绝对或相对路径问题。这是 SQL 解释器问题,默认情况下它将查找具有 .sql 扩展名的文件。
Please make sure to modified the file name to file_name.sql
请确保将文件名修改为file_name.sql
Ex: if workspace is having file name called "A", then move the file from A to "A.sql"
例如:如果工作区的文件名为“A”,则将文件从 A 移动到“A.sql”