Execute scripts by relative path in Oracle SQL Developer

混江龙づ霸主 提交于 2019-12-01 05:19:46

This approach has two components:

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

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

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

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.

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

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.

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.

Again I can't verify this but I'm sure I've done exactly this in the past...

you need to provide the path of the file as String , give the patch in double quote it will work

**

For Example @"C:\Users\Arpan Saini\Zions R2\Reports Statements and Notices\Patch\08312017_Patch_16.2.3.17\DB Scripts\snsp.sql";

**

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.

Please make sure to modified the file name to file_name.sql

Ex: if workspace is having file name called "A", then move the file from A to "A.sql"

Execution of Sql

@yourPath\yourFileName.sql
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!