在Oracle SQL Developer中按相对路径执行脚本 [英] Execute scripts by relative path in Oracle SQL Developer

查看:311
本文介绍了在Oracle SQL Developer中按相对路径执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这个问题与 Oracle SQL Developer 3.2 有关,与SQL * Plus或iSQL等无关.我做了很多搜索,但没有找到直接的答案.

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.

我有几个要自动化的脚本集合(顺便说一句,我的SQL经验很基础,而且大多基于MS).我遇到的麻烦是通过相对路径执行它们.例如,假设此设置:

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:

scripts/A/runAll.sql
       | /A1.sql
       | /A2.sql
       |
       /B/runAll.sql
         /B1.sql
         /B2.sql

我想要一个文件scripts/runEverything.sql像这样:

I would like to have a file scripts/runEverything.sql something like this:

@@/A/runAll.sql
@@/B/runAll.sql

scripts/A/runAll.sql:

scripts/A/runAll.sql:

@@/A1.sql
@@/A2.sql

我收集的"@@"表示SQL * Plus中的相对路径.

where "@@", I gather, means relative path in SQL*Plus.

我一直在愚弄变量,但是运气不佳.使用'&1'并传入根目录,我已经能够执行类似的操作. IE.: 脚本/runEverything.sql:

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/A/runAll.sql' '&1/A'
@'&1/B/runAll.sql' '&1/B'

并通过执行以下命令调用它:

and call it by executing this:

@'c:/.../scripts/runEverything.sql' 'c:/.../scripts'

但是这里的问题是B/runAll.sql用以下路径调用:c:/.../scripts/A/B.

But the problem here has been that B/runAll.sql gets called with the path: c:/.../scripts/A/B.

那么,是否可以使用SQL Developer 进行嵌套调用,以及如何进行?

So, is it possible with SQL Developer to make nested calls, and how?

推荐答案

此方法有两个组成部分:

This approach has two components:

-将活动的SQL Developer工作表的文件夹设置为默认目录.

-Set-up the active SQL Developer worksheet's folder as the default directory.

-打开驱动程序脚本,例如runAll.sql(然后将默认目录更改为活动目录),并使用runAll.sql脚本中的相对路径来调用同级脚本.

-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.

  1. 设置脚本默认文件夹.在SQL Developer工具栏上,使用以下导航:

  1. Set-up your scripts default folder. On the SQL Developer toolbar, Use this navigation:

工具>首选项

在首选项对话框中,导航到数据库">工作表">选择默认路径以查找脚本".

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}"

"${file.dir}"

创建一个脚本文件并将所有关联的脚本放入其中:

Create a script file and place all scripts associated in it:

runAll.sql

runAll.sql

A1.sql

A2.sql

runAll.sql的内容包括:

The content of runAll.sql would include:

@ A1.sql;

@A1.sql;

@ A2.sql;

@A2.sql;

要测试这种方法,请在SQL Developer中单击文件",然后导航并打开script \ runAll.sql文件.

To test this approach, in SQL Developer, click on File and navigate and open the script\runAll.sql file.

下一步,选择所有(在工作表上),然后执行.

Next, select all (on the worksheet), and execute.

通过导航和打开runAll.sql工作表的动作,默认文件夹变为脚本".

Through the act of navigating and opening the runAll.sql worksheet, the default file folder becomes "script".

这篇关于在Oracle SQL Developer中按相对路径执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆