Search code examples
oracle-databasesqlplus

How to call nested script in sqlplus


I have following script hierarchy.

Scripts/master.sql
Scripts/GB/gb.sql
Scripts/GB/user1/insert.sql

master.sql contains simple @script to call gb.sql e.g.

@GB/gb.sql

gb.sql contains below

@user1/insert.sql

The problem is that if i run master.sql from Scripts directory, i get below error:

unable to find insert.sql

Whereas if I execute gb.sql from GB directory, ir run successfully. Can you please help me?


Solution

  • SQL*Plus directories are always reletive to the original working directory. Your scripts will need to repeat the full path from the working directory each time.

    Change gb.sql to:

    @GB/user1/insert.sql
    

    The @@ can be used to reference files in the same directory as the running file, but @@ does not work with sub directories.